zylon-ai/private-gpt · error · ValueError

doc_id {doc_id} not found.

Error message

doc_id {doc_id} not found.

What it means

`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.

Source

Thrown at private_gpt/components/node_store/patched_document_store.py:55

        Returns:
            Dict[str, BaseDocument]: documents

        """
        json_dict = self._kvstore.get_all(collection=self._node_collection)
        return {key: json_to_doc_tree(json) for key, json in json_dict.items()}

    def get_document(self, doc_id: str, raise_error: bool = True) -> BaseNode | None:
        """Get a document from the store.

        Args:
            doc_id (str): document id
            raise_error (bool): raise error if doc_id not found

        """
        json = self._kvstore.get(doc_id, collection=self._node_collection)
        if json is None:
            if raise_error:
                raise ValueError(f"doc_id {doc_id} not found.")
            else:
                return None
        return json_to_doc_tree(json)

    async def aget_document(
        self, doc_id: str, raise_error: bool = True
    ) -> BaseNode | None:
        """Get a document from the store.

        Args:
            doc_id (str): document id
            raise_error (bool): raise error if doc_id not found

        """
        json = await self._kvstore.aget(doc_id, collection=self._node_collection)
        if json is None:
            if raise_error:
                raise ValueError(f"doc_id {doc_id} not found.")

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Pass `raise_error=False` and handle the None return if missing docs are expected
  2. Verify the doc_id exists (e.g. via `document_exists`/listing) before fetching
  3. If the doc should exist, check you are querying the same collection/store instance it was ingested into

Example fix

# before
doc = store.get_document(doc_id)  # raises if missing

# after
doc = store.get_document(doc_id, raise_error=False)
if doc is None:
    ...  # handle missing document
Defensive patterns

Strategy: try-catch

Validate before calling

if not kvstore.get(doc_id, collection=...):  # or an exists() helper
    raise KeyError(doc_id)

Try / catch

try:
    doc = store.get_document(doc_id)
except ValueError as e:
    if "not found" in str(e):
        raise HTTPException(404, detail=str(e)) from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15). Data as JSON: /api/errors/08f40cb1ad7409b0. Report an issue: GitHub.