Desired outcome
Configuring a different embedding model fails loudly instead of silently producing wrong-width vectors.
Why it matters
app/embeddings.py hardcodes the dimension globally:
DIMS = 384 # all-MiniLM-L6-v2. If you change the model, change the schema's vector(384) too.
and LocalEmbedder claims it unconditionally:
class LocalEmbedder:
dims = DIMS
def __init__(self, model_name: str = "sentence-transformers/all-MiniLM-L6-v2") -> None:
but model_name is fully user-controlled. app/config.py exposes EMBED_MODEL as an env var, and app/cli.py passes it through at lines 43, 65, and 104. Set EMBED_MODEL to any other sentence-transformers model, say all-mpnet-base-v2 at 768 dimensions, and LocalEmbedder.dims still reports 384 while embed() returns 768-wide vectors. The failure surfaces far from the cause: an opaque pgvector error on insert against the vector(384) column in app/schema.sql, or, worse, a partially ingested corpus.
The comment already tells the reader what to keep in sync. Nothing enforces it.
Steps
- In
LocalEmbedder._load(), after constructing the SentenceTransformer, read the real width with model.get_sentence_embedding_dimension() and store it on the instance.
- Raise a clear error when it does not match
DIMS, naming the model, both dimensions, and the vector(384) column in app/schema.sql that must change too.
- Make
dims a property that returns the loaded value rather than the class constant, so callers cannot read a stale 384.
- Add a note in
README.md under configuration that changing EMBED_MODEL requires a schema change and a re-ingest.
Keep the lazy import: the module deliberately avoids pulling in torch at import time, and the check belongs inside _load() for that reason.
Claiming this
Comment below to claim it. A reply usually comes within a day.
Desired outcome
Configuring a different embedding model fails loudly instead of silently producing wrong-width vectors.
Why it matters
app/embeddings.pyhardcodes the dimension globally:and
LocalEmbedderclaims it unconditionally:but
model_nameis fully user-controlled.app/config.pyexposesEMBED_MODELas an env var, andapp/cli.pypasses it through at lines 43, 65, and 104. SetEMBED_MODELto any other sentence-transformers model, sayall-mpnet-base-v2at 768 dimensions, andLocalEmbedder.dimsstill reports 384 whileembed()returns 768-wide vectors. The failure surfaces far from the cause: an opaque pgvector error on insert against thevector(384)column inapp/schema.sql, or, worse, a partially ingested corpus.The comment already tells the reader what to keep in sync. Nothing enforces it.
Steps
LocalEmbedder._load(), after constructing theSentenceTransformer, read the real width withmodel.get_sentence_embedding_dimension()and store it on the instance.DIMS, naming the model, both dimensions, and thevector(384)column inapp/schema.sqlthat must change too.dimsa property that returns the loaded value rather than the class constant, so callers cannot read a stale 384.README.mdunder configuration that changingEMBED_MODELrequires a schema change and a re-ingest.Keep the lazy import: the module deliberately avoids pulling in torch at import time, and the check belongs inside
_load()for that reason.Claiming this
Comment below to claim it. A reply usually comes within a day.