Skip to content

Commit 00d2f40

Browse files
committed
fix: improve embeddings ranking with full query context
The embeddings ranking by symbols is now performed using the complete query context including chat history, which provides more accurate results when finding relevant code sections. Also improves references check in chat UI using utils.empty helper.
1 parent 83acff6 commit 00d2f40

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

lua/CopilotChat/context.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,6 @@ function M.filter_embeddings(prompt, model, headless, embeddings)
656656

657657
notify.publish(notify.STATUS, 'Ranking embeddings')
658658

659-
-- Rank embeddings by symbols
660-
embeddings = data_ranked_by_symbols(prompt, embeddings, MIN_SYMBOL_SIMILARITY)
661-
log.debug('Ranked data:', #embeddings)
662-
for i, item in ipairs(embeddings) do
663-
log.debug(string.format('%s: %s - %s', i, item.score, item.filename))
664-
end
665-
666659
-- Build query from history and prompt
667660
local query = ''
668661
if not headless then
@@ -674,6 +667,13 @@ function M.filter_embeddings(prompt, model, headless, embeddings)
674667
end
675668
query = query .. '\n' .. prompt
676669

670+
-- Rank embeddings by symbols
671+
embeddings = data_ranked_by_symbols(query, embeddings, MIN_SYMBOL_SIMILARITY)
672+
log.debug('Ranked data:', #embeddings)
673+
for i, item in ipairs(embeddings) do
674+
log.debug(string.format('%s: %s - %s', i, item.score, item.filename))
675+
end
676+
677677
-- Embed the query
678678
table.insert(embeddings, {
679679
content = query,

lua/CopilotChat/ui/chat.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function Chat:render()
252252

253253
self:show_help(msg, last_section.start_line - last_section.end_line - 1)
254254

255-
if self.references and #self.references > 0 then
255+
if not utils.empty(self.references) then
256256
msg = 'References:\n'
257257
for _, ref in ipairs(self.references) do
258258
msg = msg .. ' ' .. ref.name .. '\n'

0 commit comments

Comments
 (0)