Spaces:
Sleeping
Sleeping
| from typing import Any, List, Tuple | |
| from app.qdrant import QdrantConnectionDb | |
| from qdrant_client import models | |
| class DocumentHandelerRepository: | |
| def __init__(self, qdrant_connection_db: QdrantConnectionDb): | |
| self.client = qdrant_connection_db.get_client() | |
| self.collection_name = qdrant_connection_db.get_collection_name() | |
| def find_points_by_document_name(self, document_name) -> List[int]: | |
| result = self.client.scroll( | |
| collection_name=self.collection_name, | |
| scroll_filter=models.Filter( | |
| must=[ | |
| models.FieldCondition( | |
| key="document_id", match=models.MatchValue(value=document_name) | |
| ) | |
| ] | |
| ), | |
| ) | |
| if result[0]: | |
| return [point.id for point in result[0]] | |
| return | |
| def delete_document_by_id(self, documents_id: List[int]) -> None: | |
| return self.client.delete( | |
| collection_name=self.collection_name, | |
| points_selector=models.PointIdsList(points=documents_id), | |
| ) | |
| def insert_points(self, points: List[models.PointStruct]) -> models.UpdateResult: | |
| return self.client.upsert( | |
| collection_name=self.collection_name, | |
| wait=True, | |
| points=points, | |
| ) | |
| def get_all_documents( | |
| self, | |
| ) -> Tuple[List[models.Record], Any]: # models.ScrollResult | |
| return self.client.scroll( | |
| collection_name=self.collection_name, | |
| with_payload=True, | |
| with_vectors=False, | |
| ) | |