Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor QdrantStore's delete method #66

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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