chore(server): improve semantic search (#12838)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Updated document-related tools in chat prompts, including new options
for document keyword and semantic search.

- **Refactor**
- Renamed and reorganized document search tools for improved clarity in
tool selection and results display.

- **Bug Fixes**
- Ensured tool identifiers and results are consistent across chat and
search features.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-06-17 15:01:02 +08:00
committed by GitHub
parent a4d929b19c
commit 09c3aa0a92
6 changed files with 34 additions and 24 deletions
@@ -20,12 +20,21 @@ export const buildDocSearchGetter = (
.can('Workspace.Read');
if (!canAccess) return undefined;
const chunks = await context.matchWorkspaceAll(options.workspace, query);
return chunks || undefined;
const docChunks = await ac
.user(options.user)
.workspace(options.workspace)
.docs(
chunks.filter(c => 'docId' in c),
'Doc.Read'
);
const fileChunks = chunks.filter(c => 'fileId' in c);
if (!docChunks.length && !fileChunks.length) return undefined;
return [...fileChunks, ...docChunks];
};
return searchDocs;
};
export const createSemanticSearchTool = (
export const createDocSemanticSearchTool = (
searchDocs: (query: string) => Promise<ChunkSimilarity[] | undefined>
) => {
return tool({
@@ -1,2 +1,2 @@
export * from './semantic-search';
export * from './doc-semantic-search';
export * from './web-search';