File size: 1,588 Bytes
47b5f0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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,
        )