Skip to content

Commit

Permalink
Remove vectors from Pinecone when deleting a document (#240)
Browse files Browse the repository at this point in the history
* Remove vectors from Pinecone when deleting a document

* Small tweaks
  • Loading branch information
homanp authored Aug 5, 2023
1 parent d278636 commit f00c174
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
8 changes: 2 additions & 6 deletions app/api/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from app.lib.auth.prisma import JWTBearer
from app.lib.documents import upsert_document, valid_ingestion_types
from app.lib.models.document import Document
from app.lib.vectorstores.base import VectorStoreBase
from app.lib.prisma import prisma

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -50,12 +51,6 @@ async def create_document(body: Document, token=Depends(JWTBearer())):
to_page=body.to_page,
user_id=token["userId"],
)
else:
logger.error("Invalid ingestion type")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Invalid ingestion type",
)
return {"success": True, "data": document}
except Exception as e:
logger.error("Couldn't create document", exc_info=e)
Expand Down Expand Up @@ -117,6 +112,7 @@ async def delete_document(documentId: str, token=Depends(JWTBearer())):
"""Delete a document"""
try:
prisma.document.delete(where={"id": documentId})
VectorStoreBase().get_database().delete(namespace=documentId)
return {"success": True, "data": None}
except Exception as e:
logger.error("Couldn't delete document with id {documentId}", exc_info=e)
Expand Down
5 changes: 4 additions & 1 deletion app/lib/vectorstores/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
environment=config("PINECONE_ENVIRONMENT"), # next to api key in console
)

pinecone.Index("superagent")
index = pinecone.Index("superagent")


class PineconeVectorstore:
Expand All @@ -23,3 +23,6 @@ def from_existing_index(self, embeddings, namespace):
return Pinecone.from_existing_index(
"superagent", embedding=embeddings, namespace=namespace
)

def delete(self, namespace):
return index.delete(delete_all=True, namespace=namespace)
35 changes: 17 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ transformers = "^4.30.2"
youtube-transcript-api = "^0.6.1"
replicate = "^0.8.3"
python-slugify = "^8.0.1"
langchain = "^0.0.218"
google-cloud-firestore = "^2.11.1"
google-auth = "^2.21.0"
llama-index = "^0.6.38.post1"
Expand All @@ -50,6 +49,7 @@ colorlog = "^6.7.0"
llama-hub = "^0.0.16"
pygithub = "^1.59.0"
gitpython = "^3.1.32"
langchain = "^0.0.252"


[build-system]
Expand Down

1 comment on commit f00c174

@vercel
Copy link

@vercel vercel bot commented on f00c174 Aug 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.