Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
perf(search): cap LanceDB's metadata cache so generation memory stops climbing (#2868)
Raghav Chamadiya7077cf0aef82
diff --git a/packages/core/src/repowise/core/persistence/vector_store/lancedb_store.py b/packages/core/src/repowise/core/persistence/vector_store/lancedb_store.pyindex 98bc56112..8dc8e3ea4 100644--- a/packages/core/src/repowise/core/persistence/vector_store/lancedb_store.py+++ b/packages/core/src/repowise/core/persistence/vector_store/lancedb_store.py@@ -23,6 +23,12 @@ __all__ = ["STORED_SNIPPET_CHARS", "LanceDBVectorStore", "read_recorded_vector_d# gigabytes before returning even though the selected result is small._SUMMARY_PATH_BATCH_SIZE = 100+# LanceDB caches each table version's manifest (default cap 1 GiB). Generation+# upserts in embedder-sized chunks, one version each, and every manifest lists+# all fragments so far, so the cache grew quadratically: about 0.55 GiB over+# 22k pages, held until exit. Reads only need the latest version.+_METADATA_CACHE_BYTES = 64 * 1024 * 1024+# ``STORED_SNIPPET_CHARS`` — how much of a page's content each row keeps — is# defined with the embed recipe and re-exported here so the historical import# path keeps working.@@ -136,7 +142,15 @@ class LanceDBVectorStore(VectorStore):"LanceDB is not installed. Install it with: pip install repowise-core[search]") from exc- self._db = await lancedb.connect_async(self._db_path)+ # ``Session`` arrived after the oldest supported LanceDB; without it+ # the connection keeps the library default.+ session_cls = getattr(lancedb, "Session", None)+ kwargs = (+ {"session": session_cls(metadata_cache_size_bytes=_METADATA_CACHE_BYTES)}+ if session_cls is not None+ else {}+ )+ self._db = await lancedb.connect_async(self._db_path, **kwargs)table_names = await self._db.table_names()if self._table_name in table_names:self._table = await self._db.open_table(self._table_name)diff --git a/tests/unit/persistence/test_vector_store.py b/tests/unit/persistence/test_vector_store.pyindex 2987dca67..eafc84284 100644--- a/tests/unit/persistence/test_vector_store.py+++ b/tests/unit/persistence/test_vector_store.py@@ -356,6 +356,32 @@ async def test_lancedb_embed_batch(tmp_path, mock_embedder):await store.close()+async def test_lancedb_connects_with_bounded_metadata_cache(tmp_path, mock_embedder, monkeypatch):+ # Every upsert adds a table version whose manifest the session caches, so+ # the library's 1 GiB default grew with the page count until exit.+ lancedb = pytest.importorskip("lancedb")+ if not hasattr(lancedb, "Session"):+ pytest.skip("LanceDB without Session keeps its default cache")+ from repowise.core.persistence.vector_store import LanceDBVectorStore++ seen: dict = {}+ original = lancedb.connect_async++ async def _spy(*args, **kwargs):+ seen.update(kwargs)+ return await original(*args, **kwargs)++ monkeypatch.setattr(lancedb, "connect_async", _spy)+ store = LanceDBVectorStore(str(tmp_path / "lance"), mock_embedder)+ try:+ await store.embed_batch([("p1", "Python async generators", {"target_path": "a.py"})])+ assert isinstance(seen.get("session"), lancedb.Session)+ assert await store.list_page_ids() == {"p1"}+ finally:+ await store.close()++class _FixedDimEmbedder:"""Deterministic embedder with a configurable output dimension."""