{"record":{"id":"12b6940877eb4db9","repo":"run-llama/llama_index","slug":"doc-id-doc-id-not-in-index","errorCode":null,"errorMessage":"doc_id {doc_id} not in index","messagePattern":"doc_id (.+?) not in index","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/document_summary/base.py","lineNumber":161,"sourceCode":"                **kwargs,\n            )\n        if retriever_mode == _RetrieverMode.LLM:\n            return LLMRetriever(\n                self, object_map=self._object_map, llm=self._llm, **kwargs\n            )\n        else:\n            raise ValueError(f\"Unknown retriever mode: {retriever_mode}\")\n\n    def get_document_summary(self, doc_id: str) -> str:\n        \"\"\"\n        Get document summary by doc id.\n\n        Args:\n            doc_id (str): A document id.\n\n        \"\"\"\n        if doc_id not in self._index_struct.doc_id_to_summary_id:\n            raise ValueError(f\"doc_id {doc_id} not in index\")\n        summary_id = self._index_struct.doc_id_to_summary_id[doc_id]\n        return self.docstore.get_node(summary_id).get_content()\n\n    def _add_nodes_to_index(\n        self,\n        index_struct: IndexDocumentSummary,\n        nodes: Sequence[BaseNode],\n        show_progress: bool = False,\n    ) -> None:\n        \"\"\"Add nodes to index.\"\"\"\n        doc_id_to_nodes = defaultdict(list)\n        for node in nodes:\n            if node.ref_doc_id is None:\n                raise ValueError(\n                    \"ref_doc_id of node cannot be None when building a document \"\n                    \"summary index\"\n                )\n            doc_id_to_nodes[node.ref_doc_id].append(node)","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/document_summary/base.py#L143-L179","documentation":"DocumentSummaryIndex.get_document_summary maps a document id to its summary node via index_struct.doc_id_to_summary_id. If the doc_id is not a key in that mapping (never inserted, different id scheme, or index rebuilt), it raises ValueError(f\"doc_id {doc_id} not in index\").","triggerScenarios":"Calling get_document_summary('some_id') with an id that was never indexed; using source Document.id_ vs the node's ref_doc_id inconsistently after transforms; querying an index loaded from storage that was built from a different corpus.","commonSituations":"Frontends persisting document ids from one index build and replaying them against a rebuilt index; inserts via index.insert() of Documents whose id_ differs from the ref_doc_id the summary index keys on; debugging hooks enumerating ids from the wrong collection.","solutions":["Check membership first: if doc_id in index.index_struct.doc_id_to_summary_id before calling.","List valid ids via index.index_struct.doc_id_to_summary_id.keys() and compare against the id you hold.","Ensure you use the same id that the documents were indexed under (Document.id_ / ref_doc_id of their nodes), and rebuild the index if the corpus changed."],"exampleFix":"# before\nsummary = index.get_document_summary(\"doc-42\")  # ValueError if absent\n\n# after\nsummary = (\n    index.get_document_summary(\"doc-42\")\n    if \"doc-42\" in index.index_struct.doc_id_to_summary_id\n    else \"(no summary for this document)\"\n)","handlingStrategy":"validation","validationCode":"if doc_id not in index.index_struct.doc_id_to_summary_id:\n    available = list(index.index_struct.doc_id_to_summary_id)[:10]\n    raise KeyError(f\"{doc_id} not indexed; sample ids: {available}\")","typeGuard":"def doc_has_summary(index, doc_id: str) -> bool:\n    return doc_id in index.index_struct.doc_id_to_summary_id","tryCatchPattern":"try:\n    summary = index.get_document_summary(doc_id)\nexcept ValueError:\n    summary = None  # handle unknown document gracefully in the UI","preventionTips":["Check membership in doc_id_to_summary_id before lookups.","Regenerate persisted doc-id lists whenever the index is rebuilt."],"tags":["document-summary-index","lookup","doc-id","validation"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}