fix: include project in ChromaDB where clause for vector search (#1112)
When searching with a project parameter, the ChromaDB vector query was not filtering by project. It only filtered by doc_type. This caused larger projects to dominate the top-N results returned by ChromaDB, effectively crowding out results from smaller projects before the post-hoc SQLite project filter could take effect. For example, with project A having 19,000 embeddings and project B having 700, a search scoped to project B would return mostly project A results from ChromaDB. After SQLite filtered by project, only 1-3 results from B would survive instead of the expected 20+. The fix adds the project to the ChromaDB where clause using $and when both doc_type and project filters are needed. This is applied in both ChromaSearchStrategy.buildWhereFilter() and SearchManager.search(). Co-authored-by: TARS <tars@openclaw.local>
This commit is contained in:
@@ -213,6 +213,52 @@ describe('ChromaSearchStrategy', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should include project in Chroma where clause when specified', async () => {
|
||||
const options: StrategySearchOptions = {
|
||||
query: 'test query',
|
||||
project: 'my-project'
|
||||
};
|
||||
|
||||
await strategy.search(options);
|
||||
|
||||
expect(mockChromaSync.queryChroma).toHaveBeenCalledWith(
|
||||
'test query',
|
||||
100,
|
||||
{ project: 'my-project' }
|
||||
);
|
||||
});
|
||||
|
||||
it('should combine doc_type and project with $and when both specified', async () => {
|
||||
const options: StrategySearchOptions = {
|
||||
query: 'test query',
|
||||
searchType: 'observations',
|
||||
project: 'my-project'
|
||||
};
|
||||
|
||||
await strategy.search(options);
|
||||
|
||||
expect(mockChromaSync.queryChroma).toHaveBeenCalledWith(
|
||||
'test query',
|
||||
100,
|
||||
{ $and: [{ doc_type: 'observation' }, { project: 'my-project' }] }
|
||||
);
|
||||
});
|
||||
|
||||
it('should not include project filter when project is not specified', async () => {
|
||||
const options: StrategySearchOptions = {
|
||||
query: 'test query',
|
||||
searchType: 'observations'
|
||||
};
|
||||
|
||||
await strategy.search(options);
|
||||
|
||||
expect(mockChromaSync.queryChroma).toHaveBeenCalledWith(
|
||||
'test query',
|
||||
100,
|
||||
{ doc_type: 'observation' }
|
||||
);
|
||||
});
|
||||
|
||||
it('should return empty result when no query provided', async () => {
|
||||
const options: StrategySearchOptions = {
|
||||
query: undefined
|
||||
|
||||
Reference in New Issue
Block a user