Implement ANN index using HNSW algorithm and update related tests

- Added ANNIndex class for approximate nearest neighbor search using HNSW.
- Integrated ANN index with VectorStore for enhanced search capabilities.
- Updated test suite for ANN index, including tests for adding, searching, saving, and loading vectors.
- Modified existing tests to accommodate changes in search performance expectations.
- Improved error handling for file operations in tests to ensure compatibility with Windows file locks.
- Adjusted hybrid search performance assertions for increased stability in CI environments.
This commit is contained in:
catlog22
2025-12-19 10:35:29 +08:00
parent 9f6e6852da
commit 5e91ba6c60
15 changed files with 1463 additions and 172 deletions

View File

@@ -166,6 +166,7 @@ def login_handler(credentials: dict) -> bool:
conn.commit()
# Generate embeddings
vector_store = None
try:
from codexlens.semantic.embedder import Embedder
from codexlens.semantic.vector_store import VectorStore
@@ -192,12 +193,19 @@ def login_handler(credentials: dict) -> bool:
except Exception as exc:
pytest.skip(f"Failed to generate embeddings: {exc}")
finally:
if vector_store is not None:
vector_store.close()
yield db_path
store.close()
if db_path.exists():
db_path.unlink()
# Ignore file deletion errors on Windows (SQLite file lock)
try:
if db_path.exists():
db_path.unlink()
except PermissionError:
pass # Ignore Windows file lock errors
def test_pure_vector_with_embeddings(self, db_with_embeddings):
"""Test pure vector search returns results when embeddings exist."""