Skip to content

Commit

Permalink
refresh function corrected, deleting document working with opensearch (
Browse files Browse the repository at this point in the history
  • Loading branch information
withub-TanmayAgrawal authored Sep 25, 2023
1 parent 0b016a6 commit 33b49de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## Unreleased

### Bug Fixes / Nits
- Fixed `refresh_ref_docs()` bug with order of operations (#7664)

## [0.8.33] - 2023-09-25

### New Features
Expand Down
12 changes: 7 additions & 5 deletions llama_index/indices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ def update_ref_doc(self, document: Document, **update_kwargs: Any) -> None:
"""
with self._service_context.callback_manager.as_trace("update"):
self.delete_ref_doc(
document.get_doc_id(), **update_kwargs.pop("delete_kwargs", {})
document.get_doc_id(),
delete_from_docstore=True,
**update_kwargs.pop("delete_kwargs", {}),
)
self.insert(document, **update_kwargs.pop("insert_kwargs", {}))

Expand Down Expand Up @@ -309,14 +311,14 @@ def refresh_ref_docs(
existing_doc_hash = self._docstore.get_document_hash(
document.get_doc_id()
)
if existing_doc_hash != document.hash:
if existing_doc_hash is None:
self.insert(document, **update_kwargs.pop("insert_kwargs", {}))
refreshed_documents[i] = True
elif existing_doc_hash != document.hash:
self.update_ref_doc(
document, **update_kwargs.pop("update_kwargs", {})
)
refreshed_documents[i] = True
elif existing_doc_hash is None:
self.insert(document, **update_kwargs.pop("insert_kwargs", {}))
refreshed_documents[i] = True

return refreshed_documents

Expand Down
5 changes: 4 additions & 1 deletion llama_index/indices/vector_store/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
An index that that is built on top of an existing vector store.
"""

import logging
from typing import Any, Dict, List, Optional, Sequence

from llama_index.async_utils import run_async_tasks
Expand All @@ -17,6 +17,8 @@
from llama_index.storage.storage_context import StorageContext
from llama_index.vector_stores.types import VectorStore

logger = logging.getLogger(__name__)


class VectorStoreIndex(BaseIndex[IndexDict]):
"""Vector Store Index.
Expand Down Expand Up @@ -281,6 +283,7 @@ def delete_ref_doc(
if ref_doc_info is not None:
for node_id in ref_doc_info.node_ids:
self._index_struct.delete(node_id)
self._vector_store.delete(node_id)

# delete from docstore only if needed
if (
Expand Down

0 comments on commit 33b49de

Please sign in to comment.