main
md 53 lines 2.96 KB
Rendered Raw
1 # vector_db.py DOX
2
3 ## Purpose
4
5 - Own the `vector_db.py` helper module.
6 - This module wraps FAISS vector storage, retrieval, and comparator behavior.
7 - Keep this file-level DOX profile synchronized with `vector_db.py` because this directory is intentionally flat.
8
9 ## Ownership
10
11 - `vector_db.py` owns the runtime implementation.
12 - `vector_db.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation.
13 - Classes:
14 - `MyFaiss` (`FAISS`)
15 - `get_by_ids(self, ids: Sequence[str]) -> List[Document]`
16 - `async aget_by_ids(self, ids: Sequence[str]) -> List[Document]`
17 - `get_all_docs(self) -> dict[str, Document]`
18 - `VectorDB` (no explicit base class)
19 - `async search_by_similarity_threshold(self, query: str, limit: int, threshold: float, filter: str=...)`
20 - `async search_by_metadata(self, filter: str, limit: int=...) -> list[Document]`
21 - `async insert_documents(self, docs: list[Document])`
22 - `async delete_documents_by_ids(self, ids: list[str])`
23 - Top-level functions:
24 - `format_docs_plain(docs: list[Document]) -> list[str]`
25 - `cosine_normalizer(val: float) -> float`
26 - `get_comparator(condition: str)`
27
28 ## Runtime Contracts
29
30 - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
31 - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
32 - Observed side-effect areas: filesystem deletion.
33 - Imported dependency areas include: `agent`, `faiss`, `helpers`, `langchain.embeddings`, `langchain.storage`, `langchain_community.docstore.in_memory`, `langchain_community.vectorstores`, `langchain_community.vectorstores.utils`, `langchain_core.documents`, `simpleeval`, `typing`.
34
35 ## Key Concepts
36
37 - Important called helpers/classes observed in the source: `self.get_by_ids`, `agent.get_embedding_model`, `self._get_embeddings`, `faiss.IndexFlatIP`, `MyFaiss`, `get_comparator`, `self.db.get_all_docs`, `InMemoryByteStore`, `CacheBackedEmbeddings.from_bytes_store`, `self.db.asearch`, `comparator`, `guids.generate_id`, `zip`, `self.db.add_documents`, `self.db.aget_by_ids`, `simple_eval`, `self.embeddings.embed_query`, `InMemoryDocstore`, `self.db.adelete`.
38 - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
39
40 ## Work Guidance
41
42 - Preserve public helper APIs used by core code and plugins unless every caller is updated.
43 - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded.
44 - Prefer adding cohesive helper functions here only when behavior is reused across modules.
45
46 ## Verification
47
48 - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers.
49 - No direct test reference was found by name search; choose the nearest behavioral test or perform a focused smoke check.
50
51 ## Child DOX Index
52
53 No child DOX files.