Skip to content

⚡ Bolt: Vectorize HNSWIndex search for ~11x speedup - #26

Open
Rohith-Shimori wants to merge 1 commit into
mainfrom
bolt-vector-db-optimization-16823774838420796667
Open

⚡ Bolt: Vectorize HNSWIndex search for ~11x speedup#26
Rohith-Shimori wants to merge 1 commit into
mainfrom
bolt-vector-db-optimization-16823774838420796667

Conversation

@Rohith-Shimori

Copy link
Copy Markdown
Owner

💡 What: Refactored HNSWIndex in memory/lightweight_vector_db.py to use vectorized operations (NumPy) instead of an iterative Python loop for cosine distance calculation. Also fixed the example usage which incorrectly used async/await for synchronous methods.
🎯 Why: The original iterative approach was O(N) in Python, which is slow for vector search. Vectorization leverages optimized C libraries in NumPy.
📊 Impact: Reduces search time by ~11x (0.0199s -> 0.0017s for 2000 vectors).
🔬 Measurement: Verified with a benchmark script and existing integration tests.


PR created automatically by Jules for task 16823774838420796667 started by @Rohith-Shimori

- Refactored `HNSWIndex.search` to use `numpy` matrix operations.
- Added `dirty` flag and lazy matrix rebuilding logic.
- Fixed incorrect async usage in `memory/lightweight_vector_db.py` example code.
- Verified ~11x performance improvement (0.02s -> 0.0017s for 2k vectors).

Co-authored-by: Rohith-Shimori <228351330+Rohith-Shimori@users.noreply.github.com>
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