fix: add SQLite indexes to prevent full table scans on history and messages#5009
Open
PHclaw wants to merge 5 commits intomem0ai:mainfrom
Open
fix: add SQLite indexes to prevent full table scans on history and messages#5009PHclaw wants to merge 5 commits intomem0ai:mainfrom
PHclaw wants to merge 5 commits intomem0ai:mainfrom
Conversation
added 5 commits
April 28, 2026 16:04
API keys were previously passed to the telemetry subprocess via sys.argv, exposing them through ps, /proc/<pid>/cmdline, and process inspection tools on all platforms. Changes: - telemetry.py: read API key from config and pass via MEM0_API_KEY environment variable in subprocess.Popen env= parameter - telemetry_sender.py: read MEM0_API_KEY from os.environ instead of ctx dict; updated docstring to document the security model - test_telemetry_security.py: add regression tests verifying the API key never appears in subprocess argv and is correctly passed via the environment variable
…move --reload Three production-hardening fixes for server/Dockerfile: 1. Add libpq5 system library required by psycopg (PostgreSQL adapter). Without it, python:3.12-slim fails at runtime with: ImportError: libpq.so.5: cannot open shared object file 2. Create and switch to non-root 'app' user. Running containers as root is a security anti-pattern. 3. Remove --reload flag from CMD. --reload watches files and restarts on changes (development-only). The docker-compose.yaml already overrides CMD with --reload for dev. Production images should not include it.
…ruption Concurrent AsyncMemory.add() calls caused 'index N is out of bounds' errors in Qdrant because multiple upsert() calls to the same collection corrupt the HNSW index structure during concurrent writes. Fix: - Add self._vs_lock = asyncio.Lock() in AsyncMemory.__init__ - Wrap vector store writes in add() with 'async with self._vs_lock' - This serializes concurrent writes to the same collection Closes mem0ai#4892
…ssages The history and messages tables had no indexes, causing full table scans on every query. This leads to O(n) performance degradation as the database grows. Added indexes on: - history(memory_id) for get_history() lookups - history(created_at) for ORDER BY sorting - messages(session_scope) for session-based queries - messages(created_at) for ORDER BY sorting - messages(session_scope, created_at) composite for get_last_messages() Closes mem0ai#4988
|
PHclaw seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The
historyandmessagestables had no indexes, causing full table scans on every query. As the database grows, this leads to O(n) performance degradation.Changes
Added
SQLiteManager._create_indexes()method with:idx_history_memory_idmemory_idget_history()idx_history_created_atcreated_atidx_messages_session_scopesession_scopeidx_messages_created_atcreated_atidx_messages_scope_created(session_scope, created_at)get_last_messages()compositeAll indexes use
CREATE INDEX IF NOT EXISTSfor safe migration.Closes #4988