{"record":{"id":"28216f05c52f0d43","repo":"open-webui/open-webui","slug":"pgvector-collection-is-not-configured","errorCode":null,"errorMessage":"pgvector collection is not configured","messagePattern":"pgvector collection is not configured","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"backend/open_webui/retrieval/external.py","lineNumber":224,"sourceCode":"\n\nasync def _retrieve_pgvector(connection, auth_config, knowledge, query, count, embedding_function) -> list[dict]:\n    try:\n        import psycopg\n        from pgvector.psycopg import register_vector\n        from psycopg.rows import dict_row\n    except ImportError as exc:\n        raise RuntimeError('psycopg and pgvector are required for pgvector retrieval') from exc\n\n    if not embedding_function:\n        raise RuntimeError('Embedding function is not configured')\n\n    config = connection.get('config') or {}\n    external = (knowledge.meta or {}).get('external', {})\n    source = external.get('source') or {}\n    collection_name = source.get('name')\n    if not collection_name:\n        raise RuntimeError('pgvector collection is not configured')\n    source_config = _source_config(knowledge)\n    table_name = source_config.get('table_name') or 'document_chunk'\n    collection_field = source_config.get('collection_field') or 'collection_name'\n    content_field = source_config.get('content_field') or 'text'\n    vector_field = source_config.get('vector_field') or 'vector'\n    metadata_field = source_config.get('metadata_field') or 'vmetadata'\n    document_id_field = source_config.get('document_id_field') or 'id'\n\n    vector = await embedding_function(query, prefix=RAG_EMBEDDING_QUERY_PREFIX)\n\n    def _search():\n        from psycopg import sql\n\n        table_identifier = sql.SQL('.').join(\n            sql.Identifier(_safe_identifier(part, 'table name')) for part in table_name.split('.')\n        )\n        collection_identifier = sql.Identifier(_safe_identifier(collection_field, 'collection field'))\n        content_identifier = sql.Identifier(_safe_identifier(content_field, 'content field'))","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/open-webui/open-webui/blob/01f4282f1ffe0d6212f58d3afbeae21fffd0c4be/backend/open_webui/retrieval/external.py#L206-L242","documentation":"Raised by _retrieve_pgvector when knowledge.meta.external.source.name is empty. In the pgvector path this value is used (along with table_name/collection_field from source_config) to locate the row set to search in Postgres; without a collection name the SQL cannot be scoped. The knowledge entry's external metadata is incomplete.","triggerScenarios":"Retrieval with a KnowledgeModel whose meta.external.source.name is missing/empty while the connection provider is 'pgvector'.","commonSituations":"Knowledge entry created without the collection name; the collection value in Postgres changed but the meta was blanked; API scripts writing meta.external without the source object.","solutions":["Set meta.external.source.name on the knowledge entry to the collection identifier stored in the configured collection_field (default column collection_name) of the target table.","Verify rows exist for that value: SELECT DISTINCT collection_name FROM document_chunk; using the configured table/column names.","PATCH the knowledge entry via API if the UI cannot edit it.","Require source.name at knowledge save time to prevent incomplete entries."],"exampleFix":"# before\nmeta = {\"external\": {\"connection_id\": \"pg-1\"}}\n\n# after\nmeta = {\"external\": {\"connection_id\": \"pg-1\", \"source\": {\"name\": \"kb_finance\"}}}","handlingStrategy":"validation","validationCode":"collection = ((knowledge.meta or {}).get('external', {}).get('source') or {}).get('name')\nif not collection:\n    raise ValueError('Set meta.external.source.name (collection identifier) for pgvector retrieval')\n\n# optional DB-side check\nimport psycopg\nwith psycopg.connect(conninfo, row_factory=psycopg.rows.dict_row) as conn:\n    row = conn.execute(\n        'SELECT 1 FROM document_chunk WHERE collection_name = %s LIMIT 1', (collection,)\n    ).fetchone()\n    if not row:\n        raise ValueError(f'No rows in document_chunk for collection {collection!r}')","typeGuard":"def has_pgvector_collection(knowledge) -> bool:\n    source = ((knowledge.meta or {}).get('external') or {}).get('source') or {}\n    return bool(source.get('name'))","tryCatchPattern":"try:\n    await retrieve_external_knowledge(request, knowledge, queries, count)\nexcept RuntimeError as e:\n    if 'pgvector collection is not configured' in str(e):\n        return prompt_for_collection_name(knowledge.id)\n    raise","preventionTips":["Require source.name when creating external knowledge backed by pgvector.","Verify the collection identifier exists in the configured table/column before saving.","Document the expected meta.external schema for API consumers."],"tags":["configuration","pgvector","knowledge-base","metadata","retrieval"],"backgroundTag":null,"analyzedSha":"01f4282f1ffe0d6212f58d3afbeae21fffd0c4be","analyzedAt":"2026-08-14T18:25:22.715Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}