fix(server): rerank scores calc (#13016)

fix AI-257
This commit is contained in:
DarkSky
2025-07-07 23:05:02 +08:00
committed by GitHub
parent 2d050a317f
commit 181ccf5a45
18 changed files with 329 additions and 109 deletions
@@ -39,9 +39,13 @@ export const createDocKeywordSearchTool = (
) => {
return tool({
description:
'Search all workspace documents for the exact keyword or phrase supplied and return passages ranked by textual match. Use this tool by default whenever a straightforward term-based lookup is sufficient.',
'Fuzzy search all workspace documents for the exact keyword or phrase supplied and return passages ranked by textual match. Use this tool by default whenever a straightforward term-based or keyword-base lookup is sufficient.',
parameters: z.object({
query: z.string().describe('The query to search for'),
query: z
.string()
.describe(
'The query to search for, e.g. "meeting notes" or "project plan".'
),
}),
execute: async ({ query }) => {
try {
@@ -19,13 +19,14 @@ export const buildDocSearchGetter = (
abortSignal?: AbortSignal
) => {
if (!options || !query?.trim() || !options.user || !options.workspace) {
return undefined;
return `Invalid search parameters.`;
}
const canAccess = await ac
.user(options.user)
.workspace(options.workspace)
.can('Workspace.Read');
if (!canAccess) return undefined;
if (!canAccess)
return 'You do not have permission to access this workspace.';
const [chunks, contextChunks] = await Promise.all([
context.matchWorkspaceAll(options.workspace, query, 10, abortSignal),
docContext?.matchFiles(query, 10, abortSignal) ?? [],
@@ -42,7 +43,8 @@ export const buildDocSearchGetter = (
if (contextChunks.length) {
fileChunks.push(...contextChunks);
}
if (!docChunks.length && !fileChunks.length) return undefined;
if (!docChunks.length && !fileChunks.length)
return `No results found for "${query}".`;
return [...fileChunks, ...docChunks];
};
return searchDocs;
@@ -52,16 +54,16 @@ export const createDocSemanticSearchTool = (
searchDocs: (
query: string,
abortSignal?: AbortSignal
) => Promise<ChunkSimilarity[] | undefined>
) => Promise<ChunkSimilarity[] | string | undefined>
) => {
return tool({
description:
'Retrieve conceptually related passages by performing vector-based semantic similarity search across embedded documents; call this tool only when exact keyword search fails or the user explicitly needs meaning-level matches (e.g., paraphrases, synonyms, broader concepts).',
'Retrieve conceptually related passages by performing vector-based semantic similarity search across embedded documents; use this tool only when exact keyword search fails or the user explicitly needs meaning-level matches (e.g., paraphrases, synonyms, broader concepts).',
parameters: z.object({
query: z
.string()
.describe(
'The query statement to search for, e.g. "What is the capital of France?"'
'The query statement to search for, e.g. "What is the capital of France?"\nWhen querying specific terms or IDs, you should provide the complete string instead of separating it with delimiters.\nFor example, if a user wants to look up the ID "sicDoe1is", use "What is sicDoe1is" instead of "si code 1is".'
),
}),
execute: async ({ query }, options) => {