Skip to content

feat(core): add pluggable semantic vector indexes#1141

Open
phernandez wants to merge 14 commits into
mainfrom
feat/semantic-vector-index
Open

feat(core): add pluggable semantic vector indexes#1141
phernandez wants to merge 14 commits into
mainfrom
feat/semantic-vector-index

Conversation

@phernandez

@phernandez phernandez commented Jul 22, 2026

Copy link
Copy Markdown
Member

Why

Milvus support should not require moving Basic Memory's full-text search, embedding generation,
or SQL metadata into a vendor-specific repository. The contributor work in #1041 demonstrated the
need for a clean extension boundary, while also highlighting that an in-tree Milvus dependency
would create Windows compatibility and long-term ownership costs.

This PR establishes that boundary in core so Milvus can be delivered and maintained as an external
package. It also makes the vector lifecycle explicit enough to support future multimodal embedding
providers without coupling those providers to vector storage.

What Changed

  • Added a typed SemanticVectorIndex protocol for vector initialization, persistence, deletion,
    reconciliation, and nearest-neighbour lookup.
  • Added built-in pgvector and sqlite-vec implementations behind the same contract.
  • Added Python entry-point discovery through basic_memory.semantic_vector_indexes, allowing an
    external package to provide semantic_vector_index = "milvus".
  • Added vector-index identity and readiness to the SQL chunk manifest, including a Postgres
    migration and backend-neutral project embedding status.
  • Routed semantic sync, search, reindex, stale-row cleanup, and project deletion through the new
    adapter boundary.
  • Documented the configuration and external extension contract.

Implementation Details

Core continues to own text chunking, embedding generation, and the authoritative SQL manifest.
Vector adapters receive already-computed vectors identified by stable (entity_id, chunk_key)
keys and own only vector storage and similarity search.

Writes first persist manifest rows as pending, perform adapter I/O outside the SQL transaction,
and then mark the matching index/model rows ready. Search results are hydrated through current,
ready manifest rows for the active project and embedding identity, so stale or cross-project
external matches fail closed.

SQLite always resolves to the built-in sqlite-vec adapter. Postgres defaults to pgvector and
may select an installed extension by name. Missing, duplicate, incompatible, or incorrectly scoped
extensions fail explicitly instead of silently falling back.

This does not include a Milvus implementation. The intended follow-up is for the contributor and
Zilliz team to carry the backend in a separately versioned package built on this contract. Feedback
from @zc277584121 on whether this supports the package split proposed in #1041 would be especially
helpful.

Testing

Automated

  • git show --check --oneline --no-renames HEAD: passed.
  • just fast-check: passed; type checking reported nine existing Python 3.14 asyncio deprecation
    warnings.
  • BASIC_MEMORY_ENV=test LOGFIRE_IGNORE_NO_CONFIG=1 uv run pytest -q tests/repository/test_pgvector_index.py tests/repository/test_postgres_search_repository_unit.py tests/repository/test_semantic_vector_index.py tests/repository/test_semantic_vector_sync.py tests/repository/test_sqlite_vector_search_repository.py tests/services/test_project_service_embedding_status.py tests/services/test_semantic_search.py tests/test_semantic_vector_index_migration.py test-int/test_embedding_status_vec0.py: 93 passed.
  • BASIC_MEMORY_ENV=test LOGFIRE_IGNORE_NO_CONFIG=1 just doctor: passed, including real local
    embedding generation and sqlite-vec indexing.
  • BASIC_MEMORY_ENV=test LOGFIRE_IGNORE_NO_CONFIG=1 uv run pytest -q --no-cov -m semantic test-int/semantic/test_search_diagnostics.py::test_similarity_formula_analysis: passed after updating the diagnostic to assert the adapter's normalized similarity contract instead of reading backend-native distances.
  • BASIC_MEMORY_ENV=test LOGFIRE_IGNORE_NO_CONFIG=1 just fast-test: two selected local tests
    passed and one test skipped; six selected semantic integration cases errored during fixture
    setup because Docker is not running locally, so no local Postgres result is claimed.

Manual

  • Confirmed the migration graph has a single new successor revision and every branch commit is
    signed off.

Risks / Follow-ups

  • The Postgres migration and pgvector integration need the repository's Docker-backed CI proof.
  • The entry-point contract is new public extension surface and should remain narrow while the
    first external Milvus package validates it.
  • Multimodal support still requires an embedding provider capable of producing compatible vectors;
    this PR makes vector storage replaceable but does not add such a provider.

Signed-off-by: phernandez <paul@basicmachines.co>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0470b7d9db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/services/project_service.py Outdated
Comment thread src/basic_memory/repository/search_repository_base.py Outdated
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

Resolved the failed semantic diagnostic job in signed commit 367a2f78. The test was still reading the pre-adapter best_distance private row shape; it now verifies the backend-neutral normalized best_similarity contract. Verification: the exact failing test passes locally (1 passed), and just fast-check passes. CI and Codex review are restarting on the new head.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 367a2f782a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/repository/sqlite_vec_index.py
Signed-off-by: phernandez <paul@basicmachines.co>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d780c16f28

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/repository/semantic_vector_sync.py
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8fa2182b0c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/repository/search_repository_base.py Outdated
Comment thread src/basic_memory/repository/search_repository.py Outdated
Signed-off-by: phernandez <paul@basicmachines.co>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29b738901a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/repository/search_repository_base.py Outdated
Signed-off-by: phernandez <paul@basicmachines.co>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a9dda503c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/services/project_service.py
Comment thread src/basic_memory/repository/semantic_vector_index.py
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fdc75d7f6a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/repository/search_repository_base.py Outdated
Comment thread src/basic_memory/repository/search_repository_base.py Outdated
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3cf2133d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/repository/search_repository_base.py
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c5e3a0c0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/repository/postgres_search_repository.py
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67f27ddc9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/repository/postgres_search_repository.py
Comment thread src/basic_memory/repository/search_repository_base.py
Comment thread src/basic_memory/repository/accepted_note_vector_cleanup.py
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9aa17f768

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/services/project_service.py Outdated
Comment thread src/basic_memory/repository/search_repository_base.py Outdated
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 7e7a456723

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant