{"record":{"id":"08f40cb1ad7409b0","repo":"zylon-ai/private-gpt","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":"private_gpt/components/node_store/patched_document_store.py","lineNumber":55,"sourceCode":"        Returns:\n            Dict[str, BaseDocument]: documents\n\n        \"\"\"\n        json_dict = self._kvstore.get_all(collection=self._node_collection)\n        return {key: json_to_doc_tree(json) for key, json in json_dict.items()}\n\n    def get_document(self, doc_id: str, raise_error: bool = True) -> BaseNode | None:\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_tree(json)\n\n    async def aget_document(\n        self, doc_id: str, raise_error: bool = True\n    ) -> BaseNode | None:\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:\n                raise ValueError(f\"doc_id {doc_id} not found.\")","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/node_store/patched_document_store.py#L37-L73","documentation":"`PatchedDocumentStore.get_document(doc_id, raise_error=True)` looks up `doc_id` in the KV store's node collection; when the key is absent (`kvstore.get` returns None) and `raise_error` is True (the default), it raises `ValueError('doc_id ... not found.')`. With `raise_error=False` it returns None instead.","triggerScenarios":"Fetching a document by id that was deleted, never ingested, or whose id is wrong; doc ids from a different collection/schema; default call `get_document(doc_id)` after the document was cleaned up.","commonSituations":"Stale document ids cached by clients; deletion races (doc removed between listing and fetch); wrong id format (ref_id vs doc_id confusion in llama-index).","solutions":["Pass `raise_error=False` and handle the None return if missing docs are expected","Verify the doc_id exists (e.g. via `document_exists`/listing) before fetching","If the doc should exist, check you are querying the same collection/store instance it was ingested into"],"exampleFix":"# before\ndoc = store.get_document(doc_id)  # raises if missing\n\n# after\ndoc = store.get_document(doc_id, raise_error=False)\nif doc is None:\n    ...  # handle missing document","handlingStrategy":"try-catch","validationCode":"if not kvstore.get(doc_id, collection=...):  # or an exists() helper\n    raise KeyError(doc_id)","typeGuard":null,"tryCatchPattern":"try:\n    doc = store.get_document(doc_id)\nexcept ValueError as e:\n    if \"not found\" in str(e):\n        raise HTTPException(404, detail=str(e)) from e\n    raise","preventionTips":["Default to raise_error=False and branch on None for user-facing lookups","Re-validate ids fetched from caches/indexes before hitting the document store"],"tags":["document-store","not-found","kv-store","lookup"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}