Skip to content

Conversation

@majiayu000
Copy link
Contributor

Summary

This PR fixes #1098

Changes

  • Add _foreign_keys=1 pragma to SQLite connection in pkg/memory/database/sqlite/sqlite.go
  • Add _pragma=foreign_keys(1) to SQLite connections in:
    • pkg/rag/strategy/bm25_database.go
    • pkg/rag/strategy/chunked_embeddings_database.go
    • pkg/rag/strategy/semantic_embeddings_database.go
  • Add _foreign_keys=1 pragma to SQLite connection in pkg/session/store.go
  • Add tests to verify foreign key constraints are enforced and CASCADE deletions work correctly

Why

SQLite does not enforce foreign key constraints by default. Without explicitly enabling them via PRAGMA foreign_keys = ON, ON DELETE CASCADE constraints are silently ignored, leading to orphan records in the database.

Testing

  • Added TestChunkedVectorDB_ForeignKeyCascadeDelete - verifies CASCADE deletion works
  • Added TestChunkedVectorDB_ForeignKeyConstraintEnforced - verifies constraint violations are rejected

Add _foreign_keys=1 pragma to all SQLite connections to enable
foreign key constraint enforcement. Without this setting, SQLite
silently ignores foreign key constraints and ON DELETE CASCADE
does not work as expected.

Fixes docker#1098

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: majiayu000 <[email protected]>
@majiayu000 majiayu000 requested a review from a team as a code owner December 30, 2025 12:09
@dgageot
Copy link
Member

dgageot commented Dec 30, 2025

@majiayu000 the linter is not happy :-)

Signed-off-by: David Gageot <[email protected]>
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.

[Detail Bug] SQLite foreign keys not enabled; CASCADE deletions silently fail, leaving orphaned chunks and stale search results

3 participants