Skip to content

Commit c8741c9

Browse files
committed
feat(nvim): Add deduplication option to query tool
1 parent 90cc844 commit c8741c9

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local logger = vc_config.logger
1010

1111
local job_runner = nil
1212

13-
---@alias QueryToolArgs { project_root:string, count: integer, query: string[], allow_summary: boolean }
13+
---@alias QueryToolArgs { project_root:string, count: integer, query: string[], allow_summary: boolean, deduplicate: boolean }
1414

1515
---@type VectorCode.CodeCompanion.QueryToolOpts
1616
local default_query_options = {
@@ -257,7 +257,12 @@ local function generate_summary(result, summarise_opts, cmd, callback)
257257
end)
258258
:totable())
259259

260-
if summarise_opts.enabled and cmd.allow_summary and type(callback) == "function" then
260+
if
261+
summarise_opts.enabled
262+
and cmd.allow_summary
263+
and type(callback) == "function"
264+
and #result > 0
265+
then
261266
---@type CodeCompanion.Adapter
262267
local adapter =
263268
vim.deepcopy(require("codecompanion.adapters").resolve(summarise_opts.adapter))
@@ -381,7 +386,7 @@ return check_cli_wrap(function(opts)
381386
end
382387
end
383388

384-
if opts.no_duplicate and agent.chat.refs ~= nil then
389+
if opts.no_duplicate and agent.chat.refs ~= nil and action.deduplicate then
385390
-- exclude files that has been added to the context
386391
local existing_files = { "--exclude" }
387392
for _, ref in pairs(agent.chat.refs) do
@@ -416,7 +421,11 @@ return check_cli_wrap(function(opts)
416421
summary_opts.enabled = summary_opts.enabled(agent.chat, result) --[[@as boolean]]
417422
end
418423

419-
if opts.no_duplicate and not summary_opts.enabled then
424+
if
425+
opts.no_duplicate
426+
and not summary_opts.enabled
427+
and action.deduplicate
428+
then
420429
-- NOTE: deduplication in summary mode prevents the model from requesting
421430
-- the same content without summarysation.
422431
result = filter_results(result, agent.chat)
@@ -496,8 +505,22 @@ Leave this to `true` by default.
496505
Set this to `false` only if you've been instructed by the user to not enable summarisation, or if the summary is missing information that you'd need for the current task.
497506
]],
498507
},
508+
deduplicate = {
509+
type = "boolean",
510+
description = [[
511+
Set this to `false` to deduplicate the search results with references in the chat context.
512+
Default to `true`.
513+
DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RESULTS.
514+
]],
515+
},
516+
},
517+
required = {
518+
"query",
519+
"count",
520+
"project_root",
521+
"allow_summary",
522+
"deduplicate",
499523
},
500-
required = { "query", "count", "project_root", "allow_summary" },
501524
additionalProperties = false,
502525
},
503526
strict = true,
@@ -548,6 +571,17 @@ Set this to `false` only if you've been instructed by the user to not enable sum
548571
logger.info(
549572
("CodeCompanion tool with command %s finished."):format(vim.inspect(cmd))
550573
)
574+
if vim.tbl_isempty(stdout.raw_results) then
575+
logger.info("CodeCompanion query tool recieved empty result.")
576+
return agent.chat:add_tool_output(
577+
self,
578+
string.format(
579+
"`%s` tool returned empty result. Please retry without deduplication.",
580+
tool_name
581+
),
582+
"**VectorCode `query` Tool**: Retrieved 0 result. Retrying..."
583+
)
584+
end
551585
agent.chat:add_tool_output(
552586
self,
553587
stdout.summary

0 commit comments

Comments
 (0)