Skip to content

Commit e50e227

Browse files
committed
Add error handling and logging for embedding model dimension mismatch in DatabaseKnowledgeQdrant
1 parent e1f0430 commit e50e227

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

camel_database_agent/knowledge/knowledge_qdrant.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import random
23
from typing import List, Optional, Union
34

@@ -9,6 +10,8 @@
910
from camel_database_agent.database.schema import QueryRecord
1011
from camel_database_agent.knowledge.knowledge import DatabaseKnowledge
1112

13+
logger = logging.getLogger(__name__)
14+
1215

1316
class DatabaseKnowledgeQdrant(DatabaseKnowledge):
1417
def __init__(
@@ -18,24 +21,38 @@ def __init__(
1821
path: Optional[str] = None,
1922
):
2023
self.path = path
21-
super().__init__(
22-
embedding=embedding,
23-
model=model,
24-
table_storage=QdrantStorage(
24+
try:
25+
table_storage = QdrantStorage(
2526
vector_dim=embedding.get_output_dim(),
2627
collection_name="table_documents",
2728
path=path if path else ":memory:",
28-
),
29-
data_storage=QdrantStorage(
29+
)
30+
data_storage = QdrantStorage(
3031
vector_dim=embedding.get_output_dim(),
3132
collection_name="data_documents",
3233
path=path if path else ":memory:",
33-
),
34-
query_storage=QdrantStorage(
34+
)
35+
query_storage = QdrantStorage(
3536
vector_dim=embedding.get_output_dim(),
3637
collection_name="query_documents",
3738
path=path if path else ":memory:",
38-
),
39+
)
40+
except ValueError as e:
41+
logger.error(
42+
"Adjust your embedding model to output vectors with "
43+
"the same dimensions as the existing collection. "
44+
"Alternatively, delete the existing collection and "
45+
"recreate it with your current embedding dimensions "
46+
"(note: this will result in the loss of all existing "
47+
"data)."
48+
)
49+
raise e
50+
super().__init__(
51+
embedding=embedding,
52+
model=model,
53+
table_storage=table_storage,
54+
data_storage=data_storage,
55+
query_storage=query_storage,
3956
)
4057

4158
def clear(self) -> None:

0 commit comments

Comments
 (0)