Skip to content

Commit

Permalink
Refactor QdrantStore's delete method (#66)
Browse files Browse the repository at this point in the history
- Simplify the delete method by removing dependency on langchain_qdrant and directly using QdrantClient for deletion.
- Adjust return type to None for consistency.
  • Loading branch information
StreetLamb authored Jul 2, 2024
1 parent 2ed62b2 commit cb0ebc2
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions backend/app/core/graph/rag/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from typing import Any

import pymupdf4llm # type: ignore[import-untyped]
from langchain_community.embeddings.fastembed import FastEmbedEmbeddings
from langchain_core.documents import Document
from langchain_qdrant import Qdrant
from langchain_text_splitters import MarkdownTextSplitter
from qdrant_client import QdrantClient
from qdrant_client.http import models as rest
Expand All @@ -18,7 +16,6 @@ class QdrantStore:
A class to handle uploading and searching documents in a Qdrant vector store.
"""

embeddings = FastEmbedEmbeddings(model_name=settings.DENSE_EMBEDDING_MODEL) # type: ignore[call-arg]
collection_name = settings.QDRANT_COLLECTION
url = settings.QDRANT_URL

Expand Down Expand Up @@ -86,31 +83,24 @@ def _create_collection(self) -> QdrantClient:
)
return client

def _get_collection(self) -> Qdrant:
"""Get instance of an existing Qdrant collection from langchain_qdrant."""
return Qdrant.from_existing_collection(
embedding=self.embeddings,
url=self.url,
collection_name=self.collection_name,
api_key=settings.QDRANT__SERVICE__API_KEY,
)

def delete(self, upload_id: int, user_id: int) -> bool | None:
def delete(self, upload_id: int, user_id: int) -> None:
"""Delete points from collection where upload_id and user_id in metadata matches."""
qdrant = self._get_collection()
return qdrant.delete(
ids=rest.Filter( # type: ignore[arg-type]
must=[
rest.FieldCondition(
key="user_id",
match=rest.MatchValue(value=user_id),
),
rest.FieldCondition(
key="upload_id",
match=rest.MatchValue(value=upload_id),
),
]
)
self.client.delete(
collection_name=self.collection_name,
points_selector=rest.FilterSelector(
filter=rest.Filter(
must=[
rest.FieldCondition(
key="user_id",
match=rest.MatchValue(value=user_id),
),
rest.FieldCondition(
key="upload_id",
match=rest.MatchValue(value=upload_id),
),
]
)
),
)

def update(
Expand Down

0 comments on commit cb0ebc2

Please sign in to comment.