-
Notifications
You must be signed in to change notification settings - Fork 261
feat(core): add pluggable semantic vector indexes #1141
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
25 commits
Select commit
Hold shift + click to select a range
0470b7d
feat(core): add pluggable semantic vector indexes
phernandez 367a2f7
test(core): align semantic diagnostics with vector adapters
phernandez d780c16
fix(core): harden semantic reindex lifecycle
phernandez 91d5411
fix(core): reconcile orphaned sqlite vectors
phernandez e398410
fix(core): invalidate manifests when vector storage resets
phernandez 8fa2182
test(core): cover vector storage invalidation query
phernandez 29b7389
fix(core): harden project vector cleanup
phernandez 3a9dda5
fix(core): preserve vector manifests without adapters
phernandez fdc75d7
fix(core): close vector lifecycle gaps
phernandez d3cf213
fix(core): preserve vector ownership on cleanup
phernandez 4c5e3a0
fix(core): guard entity vector ownership
phernandez 67f27dd
fix(core): guard postgres vector ownership
phernandez d9aa17f
fix(core): close vector cleanup lifecycle gaps
phernandez 7e7a456
fix(core): bound vector cleanup and hydration
phernandez 2509309
chore(core): update semantic vector branch with main
phernandez aa4cf3e
fix(core): address vector lifecycle review findings
phernandez 89062ae
fix(core): forward external vector cleanup
phernandez cbf8e50
fix(core): harden vector generation isolation
phernandez 58d434f
fix(core): serialize vector generation writes
phernandez 459ee6f
fix(core): bind vector deletes to manifest generations
phernandez b6367da
fix(core): serialize project vector cleanup
phernandez 609cddf
fix(core): close external vector deletion races
phernandez 93715b2
test(core): load sqlite-vec for status assertion
phernandez 37074e3
fix(core): serialize external vector reconciliation
phernandez 582b94a
fix(core): verify physical vectors in project status
phernandez 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
78 changes: 78 additions & 0 deletions
78
src/basic_memory/alembic/versions/o8j9k0l1m2n3_add_vector_index_manifest_state.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,78 @@ | ||
| """Add vector index identity and readiness to the semantic manifest. | ||
|
|
||
| Revision ID: o8j9k0l1m2n3 | ||
| Revises: n7i8j9k0l1m2 | ||
| Create Date: 2026-07-21 00:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| from sqlalchemy import inspect | ||
|
|
||
|
|
||
| revision: str = "o8j9k0l1m2n3" | ||
| down_revision: Union[str, None] = "n7i8j9k0l1m2" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Make PostgreSQL chunk rows an authoritative vector-write manifest. | ||
|
|
||
| SQLite creates this derived table lazily at runtime. Its schema check | ||
| rebuilds older vector tables on first semantic initialization, so only the | ||
| migration-owned PostgreSQL table needs an in-place upgrade here. | ||
| """ | ||
| connection = op.get_bind() | ||
| if connection.dialect.name != "postgresql": | ||
| return | ||
| if "search_vector_chunks" not in inspect(connection).get_table_names(): | ||
| return | ||
|
|
||
| op.execute("ALTER TABLE search_vector_chunks ADD COLUMN IF NOT EXISTS vector_index TEXT") | ||
| op.execute("ALTER TABLE search_vector_chunks ADD COLUMN IF NOT EXISTS embedding_status TEXT") | ||
| op.execute("UPDATE search_vector_chunks SET vector_index = 'pgvector'") | ||
|
|
||
| tables = set(inspect(connection).get_table_names()) | ||
| if "search_vector_embeddings" in tables: | ||
| op.execute( | ||
| """ | ||
| UPDATE search_vector_chunks AS chunks | ||
| SET embedding_status = CASE | ||
| WHEN EXISTS ( | ||
| SELECT 1 FROM search_vector_embeddings AS embeddings | ||
| WHERE embeddings.chunk_id = chunks.id | ||
| ) THEN 'ready' | ||
| ELSE 'pending' | ||
| END | ||
| """ | ||
| ) | ||
| else: | ||
| op.execute("UPDATE search_vector_chunks SET embedding_status = 'pending'") | ||
|
|
||
| op.execute("ALTER TABLE search_vector_chunks ALTER COLUMN vector_index SET NOT NULL") | ||
| op.execute("ALTER TABLE search_vector_chunks ALTER COLUMN embedding_status SET NOT NULL") | ||
| op.create_check_constraint( | ||
| "ck_search_vector_chunks_embedding_status", | ||
| "search_vector_chunks", | ||
| "embedding_status IN ('pending', 'ready')", | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Remove vector index manifest state from PostgreSQL.""" | ||
| connection = op.get_bind() | ||
| if connection.dialect.name != "postgresql": | ||
| return | ||
| if "search_vector_chunks" not in inspect(connection).get_table_names(): | ||
| return | ||
|
|
||
| op.drop_constraint( | ||
| "ck_search_vector_chunks_embedding_status", | ||
| "search_vector_chunks", | ||
| type_="check", | ||
| ) | ||
| op.execute("ALTER TABLE search_vector_chunks DROP COLUMN IF EXISTS embedding_status") | ||
| op.execute("ALTER TABLE search_vector_chunks DROP COLUMN IF EXISTS vector_index") |
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
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.