Spaces:
Runtime error
Runtime error
Hussam
commited on
Commit
·
dfc575a
1
Parent(s):
fcc0368
added basic content_exists method implementation
Browse files
src/ctp_slack_bot/services/vector_database_service.py
CHANGED
@@ -19,6 +19,28 @@ class VectorDatabaseService(BaseModel): # TODO: this should not rely specificall
|
|
19 |
logger.debug("Created {}", self.__class__.__name__)
|
20 |
return self
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def store(self, text: str, embedding: List[float], metadata: Dict[str, Any]) -> str:
|
23 |
"""
|
24 |
Store text and its embedding vector in the database.
|
|
|
19 |
logger.debug("Created {}", self.__class__.__name__)
|
20 |
return self
|
21 |
|
22 |
+
def content_exists(self, text: str) -> bool:
|
23 |
+
"""
|
24 |
+
Check if a text content already exists in the database.
|
25 |
+
|
26 |
+
Args:
|
27 |
+
text: The text content to check for existence
|
28 |
+
|
29 |
+
Returns:
|
30 |
+
bool: True if the content exists, False otherwise
|
31 |
+
"""
|
32 |
+
if not self.mongo_db.initialized:
|
33 |
+
self.mongo_db.initialize()
|
34 |
+
|
35 |
+
try:
|
36 |
+
# Check if the content already exists
|
37 |
+
result = self.mongo_db.vector_collection.find_one({"text": text})
|
38 |
+
|
39 |
+
return result is not None
|
40 |
+
except Exception as e:
|
41 |
+
logger.error(f"Error checking content existence: {str(e)}")
|
42 |
+
raise
|
43 |
+
|
44 |
def store(self, text: str, embedding: List[float], metadata: Dict[str, Any]) -> str:
|
45 |
"""
|
46 |
Store text and its embedding vector in the database.
|