Skip to content

Commit 6a20a0e

Browse files
author
Zhe Yu
committed
fix(db): Upgrade chromadb version check and include enums
1 parent db10d56 commit 6a20a0e

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

src/vectorcode/database/chroma0.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@
1313
from urllib.parse import urlparse
1414

1515
import chromadb
16+
17+
if not chromadb.__version__.startswith("0.6.3"): # pragma: nocover
18+
logging.error(
19+
f"""
20+
Found ChromaDB {chromadb.__version__}, which is incompatible with your VectorCode installation. Please install vectorcode[chroma0].
21+
22+
For example:
23+
uv tool install vectorcode[chroma0]
24+
"""
25+
)
26+
sys.exit(1)
1627
import httpx
1728
from chromadb.api import AsyncClientAPI
1829
from chromadb.api.models.AsyncCollection import AsyncCollection
30+
from chromadb.api.types import IncludeEnum
1931
from chromadb.config import APIVersion, Settings
2032
from tree_sitter import Point
2133

@@ -124,16 +136,6 @@ class _Chroma0ClientManager:
124136
__clients: dict[str, _Chroma0ClientModel]
125137

126138
def __new__(cls) -> "_Chroma0ClientManager":
127-
if not chromadb.__version__.startswith("0.6.3"): # pragma: nocover
128-
_logger.error(
129-
f"""
130-
Found ChromaDB {chromadb.__version__}, which is incompatible with your VectorCode installation. Please install vectorcode[chroma0].
131-
132-
For example:
133-
uv tool install vectorcode[chroma0]
134-
"""
135-
)
136-
sys.exit(1)
137139
if cls.singleton is None:
138140
cls.singleton = super().__new__(cls)
139141
cls.singleton.__clients = {}
@@ -277,9 +279,9 @@ async def query(self):
277279
query_result = await collection.query(
278280
query_embeddings=keywords_embeddings,
279281
include=[
280-
"metadatas",
281-
"documents",
282-
"distances",
282+
IncludeEnum.metadatas,
283+
IncludeEnum.documents,
284+
IncludeEnum.distances,
283285
],
284286
n_results=query_count,
285287
where=query_filter,
@@ -433,8 +435,8 @@ async def list_collection_content(
433435
content = CollectionContent()
434436
raw_content = await collection.get(
435437
include=[
436-
"metadatas",
437-
"documents",
438+
IncludeEnum.metadatas,
439+
IncludeEnum.documents,
438440
]
439441
)
440442
metadatas = raw_content.get("metadatas", [])
@@ -527,7 +529,7 @@ async def get_chunks(self, file_path) -> list[Chunk]:
527529

528530
raw_results = await collection.get(
529531
where={"path": file_path},
530-
include=["metadatas", "documents"],
532+
include=[IncludeEnum.metadatas, IncludeEnum.documents],
531533
)
532534
assert raw_results["metadatas"] is not None
533535
assert raw_results["documents"] is not None

0 commit comments

Comments
 (0)