Skip to content

fix: resolve SQLite embedding ValueError for list type (fixes #382)#397

Open
octo-patch wants to merge 1 commit intoNevaMind-AI:mainfrom
octo-patch:fix/issue-382-sqlite-embedding-type
Open

fix: resolve SQLite embedding ValueError for list type (fixes #382)#397
octo-patch wants to merge 1 commit intoNevaMind-AI:mainfrom
octo-patch:fix/issue-382-sqlite-embedding-type

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #382

Problem

When using the SQLite backend, table creation fails with:

ValueError: <class 'list'> has no matching SQLAlchemy type

The SQLite model classes (SQLiteMemoryItemModel, SQLiteResourceModel, SQLiteMemoryCategoryModel) inherit embedding: list[float] | None from parent Pydantic models. When build_sqlite_table_model creates table models with table=True, SQLModel attempts to map all fields to SQL columns. Since SQLite has no native vector type and list has no default SQLAlchemy mapping, this raises a ValueError.

The PostgreSQL models avoid this by re-declaring embedding with sa_column=Column(Vector(), ...), but the SQLite models used a separate embedding_json field + @property pattern that left the parent embedding field unmapped.

Fix

  • Add a JSONEncodedList SQLAlchemy TypeDecorator that serializes list[float] to JSON text on write and deserializes back on read
  • Override the parent embedding field in each SQLite model with sa_column=Column(JSONEncodedList(), nullable=True), matching the PostgreSQL approach
  • Remove the now-unnecessary embedding_json field and @property getter/setter boilerplate
  • Update repository code to use row.embedding directly (the TypeDecorator handles serialization transparently)

Test

The fix can be verified by running python tests/test_sqlite.py — table creation should no longer raise ValueError.

…NevaMind-AI#382)

The SQLite models inherited embedding: list[float] from parent classes
but never overrode it with an SQLAlchemy-compatible column type. When
SQLModel tried to create table columns, list had no matching SQLAlchemy
type, raising ValueError.

Replace the embedding_json + property pattern with a JSONEncodedList
TypeDecorator that maps list[float] to TEXT via JSON serialization,
matching how PostgreSQL models use Column(Vector()) to override the
parent field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] sqlite backend embding issue

1 participant