{"record":{"id":"3f40dd7f2cfda778","repo":"run-llama/llama_index","slug":"doc-id-doc-id-not-found","errorCode":null,"errorMessage":"doc_id {doc_id} not found.","messagePattern":"doc_id (.+?) not found\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/storage/docstore/keyval_docstore.py","lineNumber":364,"sourceCode":"                ref_doc_kv_pairs,\n                collection=self._ref_doc_collection,\n                batch_size=batch_size,\n            ),\n        )\n\n    def get_document(self, doc_id: str, raise_error: bool = True) -> Optional[BaseNode]:\n        \"\"\"\n        Get a document from the store.\n\n        Args:\n            doc_id (str): document id\n            raise_error (bool): raise error if doc_id not found\n\n        \"\"\"\n        json = self._kvstore.get(doc_id, collection=self._node_collection)\n        if json is None:\n            if raise_error:\n                raise ValueError(f\"doc_id {doc_id} not found.\")\n            else:\n                return None\n        return json_to_doc(json)\n\n    async def aget_document(\n        self, doc_id: str, raise_error: bool = True\n    ) -> Optional[BaseNode]:\n        \"\"\"\n        Get a document from the store.\n\n        Args:\n            doc_id (str): document id\n            raise_error (bool): raise error if doc_id not found\n\n        \"\"\"\n        json = await self._kvstore.aget(doc_id, collection=self._node_collection)\n        if json is None:\n            if raise_error:","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/storage/docstore/keyval_docstore.py#L346-L382","documentation":"KeyValDocumentStore.get_document(doc_id, raise_error=True) raises when the key-value store has no entry for doc_id in the node collection. raise_error defaults to True; pass raise_error=False to get None back instead. The same ID namespace is shared by documents and nodes.","triggerScenarios":"docstore.get_document('some_id') where 'some_id' was never added or was deleted (delete_document / delete_ref_doc remove node entries too); also ID confusion such as querying with a ref_doc_id instead of the doc's own ID.","commonSituations":"Loading nodes by ID after partial deletion; querying a docstore backed by a fresh/ephemeral kvstore (in-memory SimpleKVStore) after a restart; stale IDs persisted in an external system pointing at cleared storage.","solutions":["Pass raise_error=False and handle None if absence is expected: docstore.get_document(doc_id, raise_error=False).","Verify existence first with docstore.document_exists(doc_id).","Check the ID kind: for source documents use get_ref_doc_info / ref_doc collection; for nodes use the node_id.","Ensure the kvstore is persistent (e.g. MongoKVStore/RedisKVStore or SimpleKVStore + persist) if IDs were created in a previous run."],"exampleFix":"# before\ndoc = docstore.get_document(doc_id)  # raises if missing\n\n# after\ndoc = docstore.get_document(doc_id, raise_error=False)\nif doc is None:\n    # re-ingest or log-and-skip\n    ...","handlingStrategy":"validation","validationCode":"def get_doc_or_none(docstore, doc_id):\n    if not docstore.document_exists(doc_id):\n        return None\n    return docstore.get_document(doc_id)","typeGuard":"def doc_exists(docstore, doc_id: str) -> bool:\n    return docstore.document_exists(doc_id)","tryCatchPattern":"try:\n    doc = docstore.get_document(doc_id)\nexcept ValueError as e:\n    if 'not found' in str(e):\n        doc = None  # tolerate absence\n    else:\n        raise","preventionTips":["Use raise_error=False when a miss is a normal case.","Back the docstore with persistent kvstore when IDs must survive restarts.","Distinguish node/doc IDs from ref_doc IDs before lookup."],"tags":["docstore","not-found","lookup","llama-index"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}