{"record":{"id":"f1c28a58bb0fb33c","repo":"zylon-ai/private-gpt","slug":"collection-is-required-in-context","errorCode":null,"errorMessage":"collection is required in context","messagePattern":"collection is required in context","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/tools/builders/semantic_search_builder.py","lineNumber":94,"sourceCode":"        prompt_builder_service: PromptBuilderService,\n    ) -> None:\n        self.settings = settings\n        self.llm_component = llm_component\n        self.vector_store_component = vector_store_component\n        self.node_store_component = node_store_component\n        self.embedding_component = embedding_component\n        self.ingest_component = ingest_component\n        self.parse_component = parse_component\n        self.prompt_builder_service = prompt_builder_service\n\n    async def _validate_context(\n        self, context_filter: ContextFilter | None\n    ) -> ContextFilter:\n        if not context_filter:\n            raise ValueError(\"context_filter is required\")\n\n        if not context_filter.collection:\n            raise ValueError(\"collection is required in context\")\n\n        # If artifacts are provided, verify the related required indexes are ready\n        # or throw an error\n        artifacts = (\n            list(set(context_filter.artifacts)) if context_filter.artifacts else None\n        )\n        if artifacts:\n            tasks: list[Coroutine[Any, Any, None]] = []\n            for artifact in artifacts:\n                vector_artifact_index = VectorArtifactIndex(\n                    collection=context_filter.collection,\n                    artifact=artifact,\n                    vector_store_component=self.vector_store_component,\n                    node_store_component=self.node_store_component,\n                    embedding_component=self.embedding_component,\n                    ingest_component=self.ingest_component,\n                    parse_component=self.parse_component,\n                )","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/tools/builders/semantic_search_builder.py#L76-L112","documentation":"ValueError from SemanticSearchToolBuilder._validate_context: a context_filter was supplied but its collection field is empty. The collection names the vector index to search, and artifacts are indexed per (collection, artifact) via VectorArtifactIndex, so an empty collection makes retrieval impossible.","triggerScenarios":"Calling the semantic search tool with a ContextFilter whose collection is None or empty string; validation happens after the context_filter presence check and before artifact index verification.","commonSituations":"Client constructs ContextFilter with only filters/artifacts and forgets collection; settings use a non-default collection name and the caller passes the default empty value; deserialization drops the field due to a schema mismatch.","solutions":["Set context_filter.collection to the target collection name (commonly \"default\") before calling the tool.","Confirm the collection exists and is the one documents were ingested into, so the search hits real data."],"exampleFix":"# before\ncontext_filter = ContextFilter(collection=\"\")\n\n# after\ncontext_filter = ContextFilter(collection=\"default\", artifacts=[...])","handlingStrategy":"validation","validationCode":"if not context_filter or not context_filter.collection:\n    raise ValueError(\"context_filter.collection must be a non-empty collection name\")","typeGuard":"def has_collection(cf) -> bool:\n    return cf is not None and isinstance(getattr(cf, \"collection\", None), str) and bool(cf.collection.strip())","tryCatchPattern":null,"preventionTips":["Always populate collection (usually \"default\") when building ContextFilter.","Validate collection against the list of ingested collections before invoking the tool."],"tags":["validation","semantic-search","collection"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}