Skip to content

Check embedding size consistency when opening existing databases - #65

Merged
gvanrossum-ms merged 5 commits into
mainfrom
copilot/check-db-embeddings-consistency
Nov 4, 2025
Merged

Check embedding size consistency when opening existing databases#65
gvanrossum-ms merged 5 commits into
mainfrom
copilot/check-db-embeddings-consistency

Conversation

Copilot AI commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Summary

Successfully implemented embedding consistency check between database and ConversationSettings.

Changes Made

1. Added Consistency Check (typeagent/storage/sqlite/provider.py)

  • Added _check_embedding_consistency() method that validates embedding sizes during initialization
  • Checks both MessageTextIndex and RelatedTermsFuzzy tables
  • Provides clear, actionable error messages when mismatches are detected
  • Only checks when data exists (empty databases are allowed to change embedding size)

2. Test Coverage (test/test_embedding_consistency.py)

  • Test for message text index mismatch detection
  • Test for related terms index mismatch detection
  • Test for empty database scenario (no error expected)
  • All tests pass successfully

3. Documentation

  • Added class-level docstring explaining the consistency check
  • Added detailed method docstring with error conditions
  • Error messages guide users to the solution

4. Code Formatting

  • Applied black formatting to all modified files per project standards

Benefits

✅ Prevents confusing NumPy shape mismatch errors at runtime
✅ Catches issues immediately during database initialization
✅ Provides clear error messages with actionable guidance
✅ Works for all code paths (demo scripts, direct API usage, etc.)
✅ No impact on empty databases or properly configured systems
✅ No security issues detected by CodeQL

Testing

  • All new tests pass (3/3)
  • All existing tests pass
  • Manual validation with realistic scenarios confirms correct behavior
  • Code review feedback addressed
  • Black formatting applied

Security Summary

CodeQL analysis found no security vulnerabilities in the changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>Check consistency between db and embeddings</issue_title>
<issue_description>When adding to a non-empty existing db, check that the length of embedding vectors in the db matches the embedding_size in the ConversationSettings.

What's the best place to put this check? In typeagent so all code benefits, even demo/*.py.</issue_description>

Comments on the Issue (you are Copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 4, 2025 16:14
Co-authored-by: gvanrossum <2894642+gvanrossum@users.noreply.github.com>
Co-authored-by: gvanrossum <2894642+gvanrossum@users.noreply.github.com>
Co-authored-by: gvanrossum <2894642+gvanrossum@users.noreply.github.com>
Copilot AI changed the title [WIP] Add consistency check between database and embeddings Check embedding size consistency when opening existing databases Nov 4, 2025
@gvanrossum

Copy link
Copy Markdown
Collaborator

Copilot you need to run black on the modified files or make format for the whole repo.

Co-authored-by: gvanrossum <2894642+gvanrossum@users.noreply.github.com>

Copilot AI commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

Copilot you need to run black on the modified files or make format for the whole repo.

Done! Applied black formatting to both modified files. See commit f8763bc.

@gvanrossum
Guido van Rossum (gvanrossum) marked this pull request as ready for review November 4, 2025 19:10
@gvanrossum-ms
gvanrossum-ms merged commit 4fac312 into main Nov 4, 2025
31 checks passed
@gvanrossum-ms
gvanrossum-ms deleted the copilot/check-db-embeddings-consistency branch November 4, 2025 19:13
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.

Check consistency between db and embeddings

3 participants