-
Notifications
You must be signed in to change notification settings - Fork 173
fix: pass embedding dimension to provider and surface sqlite-vec probe failures #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
02cfd59
fix: pass embedding dimension to provider and surface sqlite-vec prob…
happy-v587 5b5c5d7
fix: drop readiness probe logging to keep provider errors redacted
happy-v587 6229cb9
fix: surface stable redacted readiness reasons from probe failures
happy-v587 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
tests/builtin/persistence/test_sqlite_memory_vector_index.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # Copyright (c) 2026 OceanBase. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
|
|
||
| import pytest | ||
|
|
||
| from powercontext.builtin.artifacts.memory import CapabilityNotSupportedError, EmbeddingProfile | ||
| from powercontext.builtin.persistence.sqlite import SQLiteConfig, SQLiteProfile | ||
| from powercontext.builtin.persistence.sqlite.memory_index import ( | ||
| _INSERT_VECTOR_SQL, | ||
| SQLITE_MEMORY_VECTOR_TABLES, | ||
| SQLiteMemoryVectorIndex, | ||
| _pack_vector, | ||
| ) | ||
|
|
||
|
|
||
| def _profile(dimension: int) -> EmbeddingProfile: | ||
| return EmbeddingProfile( | ||
| profile_id="test-v1", | ||
| model="test", | ||
| dimension=dimension, | ||
| distance="l2", | ||
| normalization="unit", | ||
| ) | ||
|
|
||
|
|
||
| def test_vector_index_probe_clears_a_leftover_probe_row(tmp_path) -> None: | ||
| async def scenario() -> None: | ||
| async with ( | ||
| SQLiteProfile.open( | ||
| SQLiteConfig(url=f"sqlite+aiosqlite:///{tmp_path / 'memory.db'}"), | ||
| tables=SQLITE_MEMORY_VECTOR_TABLES, | ||
| load_vector_extension=True, | ||
| ) as profile, | ||
| profile.database.transaction() as connection, | ||
| ): | ||
| await connection.exec_driver_sql("CREATE VIRTUAL TABLE pc_memory_entry_vec USING vec0(embedding float[3])") | ||
| await connection.execute( | ||
| _INSERT_VECTOR_SQL, | ||
| {"vector_id": -1, "embedding": _pack_vector((0.0, 0.0, 0.0))}, | ||
| ) | ||
| await SQLiteMemoryVectorIndex(_profile(3)).initialize(connection) | ||
| leftover = ( | ||
| await connection.exec_driver_sql("SELECT count(*) FROM pc_memory_entry_vec WHERE rowid = -1") | ||
| ).scalar() | ||
| assert int(leftover) == 0 | ||
|
|
||
| asyncio.run(scenario()) | ||
|
|
||
|
|
||
| def test_vector_index_probe_reports_a_table_dimension_mismatch(tmp_path) -> None: | ||
| async def scenario() -> None: | ||
| async with ( | ||
| SQLiteProfile.open( | ||
| SQLiteConfig(url=f"sqlite+aiosqlite:///{tmp_path / 'memory.db'}"), | ||
| tables=SQLITE_MEMORY_VECTOR_TABLES, | ||
| load_vector_extension=True, | ||
| ) as profile, | ||
| profile.database.transaction() as connection, | ||
| ): | ||
| await connection.exec_driver_sql("CREATE VIRTUAL TABLE pc_memory_entry_vec USING vec0(embedding float[4])") | ||
| index = SQLiteMemoryVectorIndex(_profile(3)) | ||
| with pytest.raises(CapabilityNotSupportedError, match=r"dimension") as exc_info: | ||
| await index.initialize(connection) | ||
| message = str(exc_info.value) | ||
| assert "4" in message | ||
| assert "3" in message | ||
| assert "capability is not supported: vector" in message | ||
| assert isinstance(exc_info.value.__cause__, Exception) | ||
|
|
||
| asyncio.run(scenario()) | ||
|
|
||
|
|
||
| def test_vector_index_probe_surfaces_the_underlying_cause(tmp_path) -> None: | ||
| async def scenario() -> None: | ||
| async with ( | ||
| SQLiteProfile.open( | ||
| SQLiteConfig(url=f"sqlite+aiosqlite:///{tmp_path / 'memory.db'}"), | ||
| tables=SQLITE_MEMORY_VECTOR_TABLES, | ||
| load_vector_extension=True, | ||
| ) as profile, | ||
| profile.database.transaction() as connection, | ||
| ): | ||
| await connection.exec_driver_sql( | ||
| "CREATE TABLE pc_memory_entry_vec (rowid INTEGER PRIMARY KEY, embedding BLOB)" | ||
| ) | ||
| index = SQLiteMemoryVectorIndex(_profile(3)) | ||
| with pytest.raises(CapabilityNotSupportedError, match=r"sqlite-vec probe failed") as exc_info: | ||
| await index.initialize(connection) | ||
| cause = exc_info.value.__cause__ | ||
| assert cause is not None | ||
| assert str(cause) not in ("", "None") | ||
| assert "sqlite-vec probe failed:" in str(exc_info.value) | ||
|
|
||
| asyncio.run(scenario()) | ||
|
|
||
|
|
||
| def test_vector_index_probe_reports_the_provider_limit_for_a_fresh_oversized_dimension(tmp_path) -> None: | ||
| async def scenario() -> None: | ||
| async with ( | ||
| SQLiteProfile.open( | ||
| SQLiteConfig(url=f"sqlite+aiosqlite:///{tmp_path / 'memory.db'}"), | ||
| tables=SQLITE_MEMORY_VECTOR_TABLES, | ||
| load_vector_extension=True, | ||
| ) as profile, | ||
| profile.database.transaction() as connection, | ||
| ): | ||
| index = SQLiteMemoryVectorIndex(_profile(65536)) | ||
| with pytest.raises(CapabilityNotSupportedError, match=r"sqlite-vec probe failed") as exc_info: | ||
| await index.initialize(connection) | ||
| message = str(exc_info.value) | ||
| assert "migrate" not in message | ||
| assert "8192" in message | ||
| assert "65536" in message | ||
|
|
||
| asyncio.run(scenario()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.