Skip to content

fix: use VECTOR_STORE.DIMENSIONS for SQLAlchemy vector column size#465

Open
paralizeer wants to merge 4 commits intoplastic-labs:mainfrom
paralizeer:fix/configurable-vector-dimensions
Open

fix: use VECTOR_STORE.DIMENSIONS for SQLAlchemy vector column size#465
paralizeer wants to merge 4 commits intoplastic-labs:mainfrom
paralizeer:fix/configurable-vector-dimensions

Conversation

@paralizeer
Copy link
Copy Markdown

@paralizeer paralizeer commented Mar 30, 2026

Problem

Document and MessageEmbedding models hardcode Vector(1536):

embedding: MappedColumn[Any] = mapped_column(Vector(1536), nullable=True)

This assumes OpenAI text-embedding-3-small dimensions. Using any other embedding model produces a runtime error:

ValueError: expected 1536 dimensions, not 768

Fix

Replace Vector(1536) with Vector(settings.VECTOR_STORE.DIMENSIONS).

VECTOR_STORE.DIMENSIONS already exists (default: 1536) and is used for LanceDB/TurboPuffer — this extends it consistently to the pgvector SQLAlchemy models.

Impact

No breaking change for default deployments (DIMENSIONS defaults to 1536). Users with non-OpenAI embedding models can now set:

[vector_store]
DIMENSIONS = 768  # e.g. nomic-embed-text, all-MiniLM-L6-v2

Summary by CodeRabbit

  • Chores
    • Embedding dimensionality is now configurable via settings instead of a fixed value.
    • Gemini-based embedding requests now use the configured embedding dimension.
    • On application startup the system validates database vector column dimensions, logs mismatches or confirmations, and raises an error if stored dimensions differ from the configured value.
The Document and MessageEmbedding models hardcoded Vector(1536) which
assumes OpenAI text-embedding-3-small dimensions. This causes runtime
errors ('expected 1536 dimensions, not 768') when using embedding
providers that produce different dimensionalities (e.g. nomic-embed-text
produces 768 dims, many local models use 384 or 1024).

Fix: replace hardcoded Vector(1536) with Vector(settings.VECTOR_STORE.DIMENSIONS)
so the SQLAlchemy column type matches the configured embedding dimensions.

The VECTOR_STORE.DIMENSIONS setting already exists (default: 1536) and
is used for LanceDB/TurboPuffer — this extends it to the pgvector models.

For custom embedding models, set in config.toml:
  [vector_store]
  DIMENSIONS = 768  # match your embedding model's output dimensions
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 63064979-4a05-4c92-be89-ae70817d7ed0

📥 Commits

Reviewing files that changed from the base of the PR and between b083f81 and 014f0df.

📒 Files selected for processing (1)
  • src/main.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main.py

Walkthrough

Replaced hard-coded 1536 vector dimensionality with settings.VECTOR_STORE.DIMENSIONS for pgvector columns and Gemini embedding calls; added async startup helper check_vector_dimensions(session) that queries PostgreSQL catalogs and raises if stored pgvector dimensions differ from settings.

Changes

Cohort / File(s) Summary
Model definitions
src/models.py
Vector(1536)Vector(settings.VECTOR_STORE.DIMENSIONS) for MessageEmbedding.embedding and Document.embedding; added settings import and exported async check_vector_dimensions(session: Any) -> None which queries pg_attribute/pg_class/pg_namespace, logs missing-column warnings, logs OK on match, and raises RuntimeError if pgvector stored dimension ≠ settings.VECTOR_STORE.DIMENSIONS.
Embedding client
src/embedding_client.py
Replaced hard-coded 1536 with settings.VECTOR_STORE.DIMENSIONS for Gemini embedding requests in embed, simple_batch_embed, and _process_batch; OpenAI/OpenRouter flows unchanged.
App startup
src/main.py
Imported check_vector_dimensions and SessionLocal; added async DB session in FastAPI lifespan startup to await check_vector_dimensions(session) after cache initialization to fail fast on pgvector dimension mismatches.

Sequence Diagram(s)

sequenceDiagram
  participant App as App (lifespan)
  participant Cache as Cache init
  participant DB as Postgres DB
  participant Check as check_vector_dimensions
  participant Logger as Logger
  App->>Cache: initialize cache
  Cache-->>App: success/failure handling
  App->>DB: open async session (SessionLocal)
  DB-->>App: session
  App->>Check: await check_vector_dimensions(session)
  Check->>DB: query pg_catalog (pg_attribute/pg_class/pg_namespace)
  DB-->>Check: atttypmod rows for embedding columns
  alt settings.VECTOR_STORE.TYPE == "pgvector"
    Check->>Check: extract stored_dim from atttypmod
    alt stored_dim == settings.VECTOR_STORE.DIMENSIONS
      Check->>Logger: log OK (dimensions match)
      Check-->>App: return None
    else stored_dim != settings.VECTOR_STORE.DIMENSIONS
      Check->>Logger: log mismatch
      Check-->>App: raise RuntimeError
    end
  else
    Check-->>App: return immediately (non-pgvector backend)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇
I hopped through code with tidy paws,
Numbers loosened, freed from laws.
Settings guide the vector trail,
I checked the burrow — none shall fail.
Embeddings snug in ordered rows.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: parametrizing vector column sizes from hardcoded 1536 to use VECTOR_STORE.DIMENSIONS configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/models.py`:
- Line 390: The embedding dimensionality is hardcoded to 1536 in
embedding_client.py which can mismatch the configured VECTOR_STORE.DIMENSIONS
used by the ORM column definition (the embedding field: "embedding:
MappedColumn[Any] = mapped_column(Vector(settings.VECTOR_STORE.DIMENSIONS),
nullable=True)"). Update embedding_client.py to replace all occurrences of the
literal 1536 (e.g., the "output_dimensionality" values) with
settings.VECTOR_STORE.DIMENSIONS so Gemini embeddings respect the configured
vector size; also break the long models.py embedding column line into two
shorter parts to keep it under 88 characters (split the
mapped_column(Vector(...), nullable=True) expression across lines while
preserving the same expression and indentation).
- Line 282: The embedding column declaration uses
settings.VECTOR_STORE.DIMENSIONS but migrations hardcode Vector(1536), and the
long line exceeds 88 chars; update the model's embedding declaration formatting
so it wraps (use mapped_column(Vector(settings.VECTOR_STORE.DIMENSIONS),
nullable=True) across multiple lines) and add a startup validation function
(e.g., check_vector_dimension or in app initialization) that queries the DB
column type for the embeddings column and compares its vector dimension to
settings.VECTOR_STORE.DIMENSIONS, failing fast with a clear error if they differ
(or log and abort), so runtime configuration and the existing migrations cannot
diverge silently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2d43811-5098-4149-b3c5-ae3d916158c7

📥 Commits

Reviewing files that changed from the base of the PR and between a5423b5 and 5ebfebd.

📒 Files selected for processing (1)
  • src/models.py
- Replace all output_dimensionality: 1536 in embedding_client.py with
  settings.VECTOR_STORE.DIMENSIONS so Gemini embeddings respect config
- Wrap long embedding column declarations for readability (< 88 chars)
- Add check_vector_dimensions() startup validator that queries DB column
  type and fails fast if Alembic migrations diverge from runtime config

Co-authored-by: CodeRabbit <coderabbit@coderabbit.ai>
@paralizeer
Copy link
Copy Markdown
Author

Applied both suggestions from @coderabbitai:

  1. Replaced hardcoded 1536 in embedding_client.py — all three output_dimensionality occurrences now use settings.VECTOR_STORE.DIMENSIONS so Gemini embeddings respect the configured vector size.

  2. Added check_vector_dimensions() startup validator — queries the actual DB column type and compares it against settings.VECTOR_STORE.DIMENSIONS, raising a RuntimeError with a clear message if they diverge. This is the real footgun: Alembic migrations hardcode Vector(1536) but the ORM now reads from config — without a runtime check, mismatches fail silently during embedding operations instead of at startup.

The validator is async and takes a session, so it can be called from the app lifespan on first DB connection. Happy to wire it into the startup sequence if the team prefers that over leaving it as a utility.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Look at the current state of embedding_client.py and the startup/lifespan code
fd -e py -e ts | head -50

# Find the embedding client file
fd "embedding_client" --type f

# Find the app lifespan/startup code
rg -n "lifespan|startup|on_startup|app_startup" --type py -l

# Find check_vector_dimensions
rg -n "check_vector_dimensions" --type py -A 20 -B 2

Length of output: 4639


🏁 Script executed:

#!/bin/bash
# Check the lifespan/startup sequence in main.py
cat src/main.py

# Check embedding_client.py for the DIMENSIONS changes
cat src/embedding_client.py

# Check the full models.py around the new function
sed -n '570,620p' src/models.py

Length of output: 25136


🏁 Script executed:

#!/bin/bash
# Check db.py for session factory
cat src/db.py 2>/dev/null || fd "db.py" src/ --exec cat {}

# Check config for vector store type
rg -n "VECTOR_STORE|vector_store" src/config.py -A 3 | head -60

# Check if there's a vector store type/backend setting
rg -n "TYPE|BACKEND|provider|lancedb|turbopuffer|pgvector" src/config.py | head -30

Length of output: 4974


@paralizeer Great work on both changes — the embedding_client.py fix is clean and complete across all three call sites. A few notes before wiring the validator:


1. Two gaps in check_vector_dimensions()

a) The documents table is not checked.
Both MessageEmbedding.embedding and Document.embedding were updated in the ORM, but the validator only queries message_embeddings. A mismatch on documents would still fail silently. Consider checking both:

async def check_vector_dimensions(session: Any) -> None:
    logger = getLogger(__name__)
    expected = settings.VECTOR_STORE.DIMENSIONS

    tables_columns = [
        ("message_embeddings", "embedding"),
        ("documents", "embedding"),
    ]

    for table, column in tables_columns:
        result = await session.execute(
            text(
                "SELECT atttypmod FROM pg_attribute "
                "JOIN pg_class ON attrelid = pg_class.oid "
                "JOIN pg_namespace ON relnamespace = pg_namespace.oid "
                f"WHERE relname = :table AND attname = :column "
                "AND nspname = current_schema()"
            ),
            {"table": table, "column": column},
        )
        row = result.fetchone()
        if row is None:
            logger.warning(f"check_vector_dimensions: could not find {table}.{column}")
            continue
        actual = row[0]
        if actual != expected:
            raise RuntimeError(
                f"Vector dimension mismatch on {table}.{column}: "
                f"DB has {actual} but VECTOR_STORE.DIMENSIONS={expected}. "
                "Run Alembic migrations or update VECTOR_STORE__DIMENSIONS to match."
            )
        logger.info(f"check_vector_dimensions: {table}.{column} OK ({expected} dims)")

Note: using a parameterised query for the values avoids any SQL injection concern even though table/column names are internal constants here.

b) The check should be gated on TYPE == "pgvector".
settings.VECTOR_STORE.TYPE already exists with the Literal["pgvector", "turbopuffer", "lancedb"] constraint. On LanceDB/TurboPuffer deployments the message_embeddings table may not exist and the current code silently swallows the miss with a WARNING — which is confusing. Adding the guard makes intent explicit:

if settings.VECTOR_STORE.TYPE != "pgvector":
    return

2. Wiring into the lifespan

Here is the minimal diff against src/main.py:

# At the top of the lifespan imports block:
from src.db import SessionLocal
from src.models import check_vector_dimensions

`@asynccontextmanager`
async def lifespan(_: FastAPI):
    await initialize_telemetry_async()

    try:
        await init_cache()
    except Exception as e:
        logger.warning(
            "Error initializing cache in api process; proceeding without cache: %s", e
        )

    # Fail fast if migration dims diverge from config (pgvector only)
    if settings.VECTOR_STORE.TYPE == "pgvector":
        async with SessionLocal() as session:
            await check_vector_dimensions(session)

    try:
        yield
    finally:
        from src.vector_store import close_external_vector_store
        await close_external_vector_store()
        await close_cache()
        await engine.dispose()
        await shutdown_telemetry()

SessionLocal is already defined in src/db.py as an async_sessionmaker — it's the right handle to use here without introducing a new dependency.


3. atttypmod correctness

The comparison actual != expected is correct for pgvector. Unlike PostgreSQL's varchar(n) (which stores n + 4 in atttypmod), pgvector stores the dimension count directly, so Vector(1536) yields atttypmod == 1536.


🧠 Learnings used
Learnt from: Rajat-Ahuja1997
Repo: plastic-labs/honcho PR: 131
File: migrations/versions/d429de0e5338_adopt_peer_paradigm.py:188-194
Timestamp: 2025-06-18T15:58:51.202Z
Learning: In the migration file `migrations/versions/d429de0e5338_adopt_peer_paradigm.py`, the team has explicitly decided to accept SQL injection risks from f-string interpolation of schema names, despite the security concerns around DDL injection via the DATABASE_SCHEMA environment variable.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/embedding_client.py (1)

90-94: ⚠️ Potential issue | 🟠 Major

Add dimensions parameter to OpenAI embeddings.create() call

OpenAI's text-embedding-3-small supports a configurable dimensions parameter. The current code doesn't pass it, causing a mismatch when VECTOR_STORE.DIMENSIONS is configured to a non-default value (e.g., 768). Since the database schema enforces the configured dimensions and Gemini already respects this setting via output_dimensionality, OpenAI and OpenRouter should also pass dimensions=settings.VECTOR_STORE.DIMENSIONS to embeddings.create() for consistency.

Current code (lines 90-94)
        else:  # openai
            response = await self.client.embeddings.create(
                model=self.model, input=query
            )
            return response.data[0].embedding
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/embedding_client.py` around lines 90 - 94, The OpenAI embeddings call in
the else branch of the embedding creation doesn't pass the configured vector
dimensionality; update the call to self.client.embeddings.create to include
dimensions=settings.VECTOR_STORE.DIMENSIONS (i.e., await
self.client.embeddings.create(model=self.model, input=query,
dimensions=settings.VECTOR_STORE.DIMENSIONS)) and ensure settings is
imported/available in the scope where this method/class (the embedding client
method using self.client.embeddings.create, self.model, and query) is defined so
the returned embedding matches the DB schema.
🧹 Nitpick comments (4)
src/models.py (2)

590-590: Remove shadowed logger declaration.

Line 35 already declares a module-level logger = getLogger(__name__). This local re-declaration shadows it unnecessarily.

♻️ Proposed fix
 async def check_vector_dimensions(session: Any) -> None:
     """
     Validate that the DB vector column dimension matches VECTOR_STORE.DIMENSIONS.
     Call this at application startup to fail fast if Alembic migrations and
     runtime config have diverged.
     """
-    logger = getLogger(__name__)
     expected = settings.VECTOR_STORE.DIMENSIONS
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/models.py` at line 590, Remove the redundant local declaration `logger =
getLogger(__name__)` that shadows the existing module-level `logger`; instead,
delete that local line and use the already-declared module-level `logger`
everywhere in the surrounding function/class (keep existing log calls
unchanged). Ensure no other local variable named `logger` remains in the scope
so all logging uses the single module-level `logger`.

603-603: Line exceeds 88 characters.

As per coding guidelines, use line length of 88 characters (Black compatible).

♻️ Proposed fix
     if row is None:
-        logger.warning("check_vector_dimensions: could not find message_embeddings.embedding column")
+        logger.warning(
+            "check_vector_dimensions: could not find message_embeddings.embedding column"
+        )
         return
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/models.py` at line 603, The warning message string in logger.warning call
inside check_vector_dimensions is longer than 88 characters; shorten or rephrase
the message (e.g., "check_vector_dimensions: missing
message_embeddings.embedding column") or split into a shorter message so the
logger.warning("...") call in that function stays within the 88-character limit.
src/embedding_client.py (2)

255-255: Same line length issue as above.

♻️ Proposed fix
                 if isinstance(self.client, genai.Client):
                     response = await self.client.aio.models.embed_content(
                         model=self.model,
                         contents=[item.text for item in batch],
-                        config={"output_dimensionality": settings.VECTOR_STORE.DIMENSIONS},
+                        config={
+                            "output_dimensionality": settings.VECTOR_STORE.DIMENSIONS
+                        },
                     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/embedding_client.py` at line 255, The line setting
config={"output_dimensionality": settings.VECTOR_STORE.DIMENSIONS} is too long;
break the dictionary across multiple lines to respect max line length and match
surrounding formatting. Update the call where this appears (the argument named
config in the embedding client call) to use a multi-line dict with the key on
its own line and the value on the next (or align with other kwargs), and run the
formatter/linter so the change is consistent with the project's style.

119-119: Line may exceed 88 characters due to indentation depth.

Consider breaking the config argument across lines for Black compliance.

♻️ Proposed fix
                 if isinstance(self.client, genai.Client):
                     # Type cast needed due to genai type signature complexity
                     response = await self.client.aio.models.embed_content(
                         model=self.model,
                         contents=batch,  # pyright: ignore[reportArgumentType]
-                        config={"output_dimensionality": settings.VECTOR_STORE.DIMENSIONS},
+                        config={
+                            "output_dimensionality": settings.VECTOR_STORE.DIMENSIONS
+                        },
                     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/embedding_client.py` at line 119, The line with the config argument
(config={"output_dimensionality": settings.VECTOR_STORE.DIMENSIONS}) is too
long; split the dict across multiple lines so Black will wrap it. Replace the
single-line dict with a multi-line form such as config={
"output_dimensionality": settings.VECTOR_STORE.DIMENSIONS, } or break the call
so the config= argument is on its own line and the dict entries are indented on
subsequent lines; update the call site where config is passed to preserve
trailing commas and indentation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/models.py`:
- Around line 584-612: check_vector_dimensions only queries the
message_embeddings.embedding column; extend it to validate the
documents.embedding column too (both tables use
settings.VECTOR_STORE.DIMENSIONS) by iterating over the table names (e.g.,
["message_embeddings", "documents"]) and running the same pg_attribute query per
table, comparing each atttypmod to settings.VECTOR_STORE.DIMENSIONS and raising
the same RuntimeError if any mismatch is found; keep existing logging behavior
(warning if column not found, info when OK) and reference the same column name
"embedding" and constant settings.VECTOR_STORE.DIMENSIONS in the updated
check_vector_dimensions implementation.

---

Outside diff comments:
In `@src/embedding_client.py`:
- Around line 90-94: The OpenAI embeddings call in the else branch of the
embedding creation doesn't pass the configured vector dimensionality; update the
call to self.client.embeddings.create to include
dimensions=settings.VECTOR_STORE.DIMENSIONS (i.e., await
self.client.embeddings.create(model=self.model, input=query,
dimensions=settings.VECTOR_STORE.DIMENSIONS)) and ensure settings is
imported/available in the scope where this method/class (the embedding client
method using self.client.embeddings.create, self.model, and query) is defined so
the returned embedding matches the DB schema.

---

Nitpick comments:
In `@src/embedding_client.py`:
- Line 255: The line setting config={"output_dimensionality":
settings.VECTOR_STORE.DIMENSIONS} is too long; break the dictionary across
multiple lines to respect max line length and match surrounding formatting.
Update the call where this appears (the argument named config in the embedding
client call) to use a multi-line dict with the key on its own line and the value
on the next (or align with other kwargs), and run the formatter/linter so the
change is consistent with the project's style.
- Line 119: The line with the config argument (config={"output_dimensionality":
settings.VECTOR_STORE.DIMENSIONS}) is too long; split the dict across multiple
lines so Black will wrap it. Replace the single-line dict with a multi-line form
such as config={ "output_dimensionality": settings.VECTOR_STORE.DIMENSIONS, } or
break the call so the config= argument is on its own line and the dict entries
are indented on subsequent lines; update the call site where config is passed to
preserve trailing commas and indentation.

In `@src/models.py`:
- Line 590: Remove the redundant local declaration `logger =
getLogger(__name__)` that shadows the existing module-level `logger`; instead,
delete that local line and use the already-declared module-level `logger`
everywhere in the surrounding function/class (keep existing log calls
unchanged). Ensure no other local variable named `logger` remains in the scope
so all logging uses the single module-level `logger`.
- Line 603: The warning message string in logger.warning call inside
check_vector_dimensions is longer than 88 characters; shorten or rephrase the
message (e.g., "check_vector_dimensions: missing message_embeddings.embedding
column") or split into a shorter message so the logger.warning("...") call in
that function stays within the 88-character limit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a44177b4-5832-4208-97a3-73adc8e522e5

📥 Commits

Reviewing files that changed from the base of the PR and between 5ebfebd and 791981c.

📒 Files selected for processing (2)
  • src/embedding_client.py
  • src/models.py
- Check both message_embeddings.embedding and documents.embedding
- Gate on VECTOR_STORE.TYPE == 'pgvector' (skip for LanceDB/TurboPuffer)
- Use parameterized queries instead of f-strings
- Wire into app lifespan in main.py via SessionLocal so the check
  runs at startup before serving requests

Co-authored-by: CodeRabbit <coderabbit@coderabbit.ai>
@paralizeer
Copy link
Copy Markdown
Author

Updated with both fixes:

  1. Check both tablesmessage_embeddings.embedding and documents.embedding are both validated now. Uses parameterized queries.
  2. Gated on TYPE == "pgvector" — returns early for LanceDB/TurboPuffer deployments where the table doesn't exist.
  3. Wired into main.py lifespan — runs via SessionLocal before the app starts serving, exactly as suggested. Import moved to module-level alongside the other src.db imports.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main.py`:
- Around line 136-141: The vector-dimension check is currently executed before
entering the lifespan try/finally, so if check_vector_dimensions(session) raises
the cleanup in the finally block never runs; move the async with SessionLocal()
and await check_vector_dimensions(session) inside the lifespan try block (i.e.,
into the same try that surrounds yield) so any exception during
check_vector_dimensions still triggers the finally cleanup — adjust placement
around the existing try/yield/finally and keep using SessionLocal and
check_vector_dimensions as the identifying symbols.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 886a45bf-142c-44ee-8abf-3045e24384f8

📥 Commits

Reviewing files that changed from the base of the PR and between 791981c and b083f81.

📒 Files selected for processing (2)
  • src/main.py
  • src/models.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/models.py
Ensures cleanup (vector store, cache, engine disposal) always runs
even if the dimension check raises at startup.

Co-authored-by: CodeRabbit <coderabbit@coderabbit.ai>
@paralizeer
Copy link
Copy Markdown
Author

Fixed — moved check_vector_dimensions() inside the try/finally block so cleanup always runs even if the check raises at startup.

Also note: the documents table gap was already addressed in the previous commit (both message_embeddings and documents are now checked).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant