Skip to content

Commit

Permalink
PR feedback: loading the IndexStore from FS to delete objects from it
Browse files Browse the repository at this point in the history
  • Loading branch information
lopagela committed Nov 5, 2023
1 parent 2392372 commit 3d88c8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
8 changes: 1 addition & 7 deletions private_gpt/server/ingest/ingest_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,4 @@ def delete_ingested(doc_id: str) -> None:
from the directory specified in your configuration)
"""
service = root_injector.get(IngestService)
try:
service.delete(doc_id)
except ValueError as err:
raise HTTPException(
404, f"Document={doc_id} not found in the datastore"
) from err
return
service.delete(doc_id)
19 changes: 13 additions & 6 deletions private_gpt/server/ingest/ingest_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
StorageContext,
StringIterableReader,
VectorStoreIndex,
load_index_from_storage,
)
from llama_index.node_parser import SentenceWindowNodeParser
from llama_index.readers.file.base import DEFAULT_FILE_READER_CLS
Expand Down Expand Up @@ -170,9 +171,15 @@ def delete(self, doc_id: str) -> None:
:raises ValueError: if the document does not exist
"""
logger.info("Deleting the ingested document=%s in the doc store", doc_id)
self.storage_context.docstore.delete_ref_doc(doc_id)
# FIXME the documents are only deleted, and not in the vector store
# or index store
# self.storage_context.vector_store.delete(doc_id)
# self.storage_context.index_store.delete_index_struct(doc_id)
logger.info(
"Deleting the ingested document=%s in the doc and index store", doc_id
)

# Load the index with store_nodes_override=True to be able to delete them
index = load_index_from_storage(self.storage_context, store_nodes_override=True)

# Delete the document from the index
index.delete_ref_doc(doc_id, delete_from_docstore=True)

# Save the index
self.storage_context.persist(persist_dir=local_data_path)

0 comments on commit 3d88c8c

Please sign in to comment.