fix: keep relevance scores on knowledge tool citations (#31307)

With native function calling, citations produced by query_knowledge_files and query_chat_files never showed the relevance percentage badge, while the same knowledge base queried through classic RAG did.

The tools already return a distance per chunk, but the step that groups tool results into citation sources dropped it. Each grouped source now carries a distances list aligned with its documents, the same shape the classic RAG path emits, so the existing citation UI shows the badge without frontend changes. Chunks without a score (notes) leave the list empty, which the UI already treats as no score.

Fixes #29776
This commit is contained in:
Classic298 2026-09-27 21:21:21 +02:00 • committed by GitHub
parent 0fe9ed0d3c
commit 1c813902ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -510,6 +510,7 @@ def get_citation_source_from_tool_result(
},
'document': [],
'metadata': [],
'distances': [],
}
sources_by_file[key]['document'].append(content)
@ -521,6 +522,8 @@ def get_citation_source_from_tool_result(
**({'note_id': note_id} if note_id else {}),
}
)
if 'distance' in chunk:
sources_by_file[key]['distances'].append(chunk['distance'])
# Return all grouped sources as a list
if sources_by_file: