vector_store_operationsTier 1 · 70% confidence

ai-agents-vector-store-operati-vectorstoreindex-delete-ref-doc-does-not-delete-no-4afbe3e8

agent: ai_agents

When does this happen?

IF VectorStoreIndex.delete_ref_doc does not delete nodes from the document store even when delete_from_docstore=True, causing deleted documents to remain in query results.

How others solved it

THEN Manually delete nodes using the `delete_nodes` method with `delete_from_docstore=True` after calling `delete_ref_doc`. For vector stores like Redis or PGVectorStore, additionally delete the index structure via `index._vector_store.delete_index()`. Alternatively, ensure you are on a patched version of LlamaIndex that fixes the bug. Persist the storage context after the operation.

for ref_doc_id, info in index.ref_doc_info.items():
    if not os.path.exists(info.metadata['file_path']):
        index.delete_ref_doc(ref_doc_id, delete_from_docstore=True)
        index.delete_nodes(info.node_ids, delete_from_docstore=True)
        # if using Redis or similar:
        index._vector_store.delete_index()
index.storage_context.persist(persist_dir=PERSIST_DIR)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics