[GH-ISSUE #8472] document_chunk table missing when using PGVector #30665

Closed
opened 2026-04-25 04:55:26 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @GanizaniSitara on GitHub (Jan 10, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/8472

Installation Method

Python on Windows

Environment

  • 0.5.4 open-webui
  • Windows 10
  • Brave

Expected Behavior:

document_chunk table gets created in Postgres when starting instance with new Postgres database (using DATABASE_URL)

Actual Behavior:

document_chunk table missing

Description

white the document_chunk table is defined in the pgvector.py file, I cannot find it actually being created anywhere in the code base.

Aslo check_vector_lenght() requires the document_chunk talbe, but create_all only runs after (but even that doesn't create it_

Bug Summary:
see below for console output

Reproduction Details

Steps to Reproduce:
setup new empty postgres database
point DATABASE_URL to it
start open-webui

WORAROUND - create table manually

CREATE TABLE document_chunk (
id TEXT PRIMARY KEY,
vector VECTOR(1536),
collection_name TEXT NOT NULL,
text TEXT,
vmetadata JSONB
);

Logs and Screenshots

│ ┌────────────────────────────────────── locals ──────────────────────────────────────┐ │
│ │ PgvectorClient = <class 'open_webui.retrieval.vector.dbs.pgvector.PgvectorClient'> │ │
│ │ VECTOR_DB = 'pgvector' │ │
│ └────────────────────────────────────────────────────────────────────────────────────┘ │
│ │
│ C:\Anaconda3\envs\ollama311\Lib\site-packages\open_webui\retrieval\vector\dbs\pgvector.py:61 in init
│ │
│ 58 │ │ │ self.session.execute(text("CREATE EXTENSION IF NOT EXISTS vector;")) │
│ 59 │ │ │ │
│ 60 │ │ │ # Check vector length consistency │
│ > 61 │ │ │ self.check_vector_length() │
│ 62 │ │ │ │
│ 63 │ │ │ # Create the tables if they do not exist │
│ 64 │ │ │ # Base.metadata.create_all requires a bind (engine or connection) │
│ │
│ ┌────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────┐ │
│ │ engine = Engine(postgresql://postgres:@127.0.0.1:5432/openwebui) │ │
│ │ self = <open_webui.retrieval.vector.dbs.pgvector.PgvectorClient object at 0x0000025131E14890> │ │
│ │ SessionLocal = sessionmaker(class_='Session', autocommit=False, bind=Engine(postgresql://postgres:
@127.0.0.1:5432/openwebui), │ │
│ │ autoflush=False, expire_on_commit=False) │ │
│ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ │
│ │
│ C:\Anaconda3\envs\ollama311\Lib\site-packages\open_webui\retrieval\vector\dbs\pgvector.py:95 in check_vector_length │
│ │
│ 92 │ │ Raises an exception if there is a mismatch. │
│ 93 │ │ """ │
│ 94 │ │ metadata = MetaData() │
│ > 95 │ │ metadata.reflect(bind=self.session.bind, only=["document_chunk"]) │
│ 96 │ │ │
│ 97 │ │ if "document_chunk" in metadata.tables: │
│ 98 │ │ │ document_chunk_table = metadata.tables["document_chunk"]

Originally created by @GanizaniSitara on GitHub (Jan 10, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/8472 ## Installation Method Python on Windows ## Environment - 0.5.4 open-webui - Windows 10 - Brave ## Expected Behavior: document_chunk table gets created in Postgres when starting instance with new Postgres database (using DATABASE_URL) ## Actual Behavior: document_chunk table missing ## Description white the document_chunk table is defined in the pgvector.py file, I cannot find it actually being created anywhere in the code base. Aslo check_vector_lenght() requires the document_chunk talbe, but create_all only runs after (but even that doesn't create it_ **Bug Summary:** see below for console output ## Reproduction Details **Steps to Reproduce:** setup new empty postgres database point DATABASE_URL to it start open-webui ## WORAROUND - create table manually CREATE TABLE document_chunk ( id TEXT PRIMARY KEY, vector VECTOR(1536), collection_name TEXT NOT NULL, text TEXT, vmetadata JSONB ); ## Logs and Screenshots │ ┌────────────────────────────────────── locals ──────────────────────────────────────┐ │ │ │ PgvectorClient = <class 'open_webui.retrieval.vector.dbs.pgvector.PgvectorClient'> │ │ │ │ VECTOR_DB = 'pgvector' │ │ │ └────────────────────────────────────────────────────────────────────────────────────┘ │ │ │ │ C:\Anaconda3\envs\ollama311\Lib\site-packages\open_webui\retrieval\vector\dbs\pgvector.py:61 in __init__ │ │ │ │ 58 │ │ │ self.session.execute(text("CREATE EXTENSION IF NOT EXISTS vector;")) │ │ 59 │ │ │ │ │ 60 │ │ │ # Check vector length consistency │ │ > 61 │ │ │ self.check_vector_length() │ │ 62 │ │ │ │ │ 63 │ │ │ # Create the tables if they do not exist │ │ 64 │ │ │ # Base.metadata.create_all requires a bind (engine or connection) │ │ │ │ ┌────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────┐ │ │ │ engine = Engine(postgresql://postgres:***@127.0.0.1:5432/openwebui) │ │ │ │ self = <open_webui.retrieval.vector.dbs.pgvector.PgvectorClient object at 0x0000025131E14890> │ │ │ │ SessionLocal = sessionmaker(class_='Session', autocommit=False, bind=Engine(postgresql://postgres:***@127.0.0.1:5432/openwebui), │ │ │ │ autoflush=False, expire_on_commit=False) │ │ │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ │ │ │ │ C:\Anaconda3\envs\ollama311\Lib\site-packages\open_webui\retrieval\vector\dbs\pgvector.py:95 in check_vector_length │ │ │ │ 92 │ │ Raises an exception if there is a mismatch. │ │ 93 │ │ """ │ │ 94 │ │ metadata = MetaData() │ │ > 95 │ │ metadata.reflect(bind=self.session.bind, only=["document_chunk"]) │ │ 96 │ │ │ │ 97 │ │ if "document_chunk" in metadata.tables: │ │ 98 │ │ │ document_chunk_table = metadata.tables["document_chunk"]
Author
Owner

@beastech commented on GitHub (Jan 11, 2025):

I'm going to try that workaround for sure. Thanks for sharing that!

<!-- gh-comment-id:2585283367 --> @beastech commented on GitHub (Jan 11, 2025): I'm going to try that workaround for sure. Thanks for sharing that!
Author
Owner

@carlosnatalino commented on GitHub (Jan 14, 2025):

I also had the same issue. However, I found that the issue comes from this line:

4269df041f/backend/open_webui/retrieval/vector/dbs/pgvector.py (L95)

where it is trying to reflect the document_chunk table which may not exist:

metadata.reflect(bind=self.session.bind, only=["document_chunk"])

To fix this, I changed the line to:

metadata.reflect(bind=self.session.bind)  #, only=["document_chunk"])
<!-- gh-comment-id:2589193692 --> @carlosnatalino commented on GitHub (Jan 14, 2025): I also had the same issue. However, I found that the issue comes from this line: https://github.com/open-webui/open-webui/blob/4269df041fef62208d59babe0faae866d2bfbc3c/backend/open_webui/retrieval/vector/dbs/pgvector.py#L95 where it is trying to reflect the `document_chunk` table which may not exist: ```python metadata.reflect(bind=self.session.bind, only=["document_chunk"]) ``` To fix this, I changed the line to: ```python metadata.reflect(bind=self.session.bind) #, only=["document_chunk"]) ```
Author
Owner

@tjbck commented on GitHub (Jan 16, 2025):

Might have been addressed by @jk-f5 in dev, confirmation wanted here!

<!-- gh-comment-id:2594744002 --> @tjbck commented on GitHub (Jan 16, 2025): Might have been addressed by @jk-f5 in dev, confirmation wanted here!
Author
Owner

@jk-f5 commented on GitHub (Jan 16, 2025):

Yep, fixed in dev. See #8385.

<!-- gh-comment-id:2596058691 --> @jk-f5 commented on GitHub (Jan 16, 2025): Yep, fixed in dev. See #8385.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#30665