Skip to content

Commit b53ef99

Browse files
Zhe YuDavidyz
authored andcommitted
feat(cli): support excluding files in queries.
1 parent 7bb0b12 commit b53ef99

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/vectorcode/database/chroma0.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141

4242
def __convert_chroma_query_results(
43-
chroma_result: QueryResult, queries: list[str]
43+
chroma_result: QueryResult, queries: Sequence[str]
4444
) -> list[types.QueryResult]:
4545
"""Convert chromadb query result to in-house query results"""
4646
assert chroma_result["documents"] is not None
@@ -272,6 +272,11 @@ async def query(self, collection_path, keywords_embeddings, opts):
272272
query_count = opts.count or (
273273
await self.count(collection_path, ResultType.chunk)
274274
)
275+
query_filter = None
276+
if len(opts.excluded_files):
277+
query_filter = cast(
278+
chromadb.Where, {"path": {"$nin": list(opts.excluded_files)}}
279+
)
275280
query_result = await collection.query(
276281
query_embeddings=keywords_embeddings,
277282
include=[
@@ -280,6 +285,7 @@ async def query(self, collection_path, keywords_embeddings, opts):
280285
IncludeEnum.distances,
281286
],
282287
n_results=query_count,
288+
where=query_filter,
283289
)
284290
return __convert_chroma_query_results(query_result, opts.keywords)
285291

src/vectorcode/database/types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
from dataclasses import dataclass, field, fields
33
from enum import StrEnum
4-
from typing import Any
4+
from typing import Any, Sequence
55

66
import tabulate
77

@@ -17,9 +17,10 @@ class ResultType(StrEnum):
1717

1818
@dataclass
1919
class QueryOpts:
20-
keywords: list[str]
20+
keywords: Sequence[str]
2121
count: int | None = None
2222
return_type: ResultType = ResultType.chunk
23+
excluded_files: Sequence[str] = []
2324

2425

2526
@dataclass

0 commit comments

Comments
 (0)