Class: InMemoryVectorIndexAdapter
Defined in: adapters/in-memory/InMemoryVectorIndexAdapter.ts:32
InMemoryVectorIndexAdapter -- the vector index in a Map, for tests and the sandbox
About
A brute-force cosine search over every record: exact, and fine for a few thousand chunks.
Implements IVectorIndexAdapter so the VectorStore runs with no infrastructure. The score is (1 + cosine) / 2, 0..1
like Atlas Vector Search, so minScore means the same in a test and in production. The filters are AND-ed; libraryIds,
bookIds and tags match when the chunk has any of the listed values; libraryIds "all" = no restriction and an
empty array = no chunk matches, bookIds empty = no restriction. The constructor takes what describe reports.
Who needs it
The gateway tests (gatewayConfigBase), the dev sandbox and the cookbook's first run; a host app uses its own adapter.
Pitfalls
Production: nothing survives the process, nothing is shared between processes. Every search scans every record of the tenant: a large index belongs in a real vector database.
Implements
Constructors
Constructor
new InMemoryVectorIndexAdapter(
info):InMemoryVectorIndexAdapter
Defined in: adapters/in-memory/InMemoryVectorIndexAdapter.ts:35
Parameters
info
What describe() reports: the model and dimensions this index is created for.
Returns
InMemoryVectorIndexAdapter
Methods
deleteByDoc()
deleteByDoc(
__namedParameters):Promise<number>
Defined in: adapters/in-memory/InMemoryVectorIndexAdapter.ts:86
deleteByDoc -- removes every chunk of a document
About
By
docIdwithin the tenant; returns the count.
A re-ingest deletes first, so a shorter document leaves no stale chunks behind.
Who needs it
VectorStore.deleteByDoc.
Parameters
__namedParameters
docId
string
tenantId
string
Returns
Promise<number>
Implementation of
IVectorIndexAdapter.deleteByDoc
describe()
describe():
Promise<IVectorIndexInfo>
Defined in: adapters/in-memory/InMemoryVectorIndexAdapter.ts:185
describe -- model and dimensions of the index
About
What the index was created with.
Compared with the Embedder's model before every ingest, so a vector of another model is never written.
Who needs it
VectorStore.describeIndex.
Returns
Promise<IVectorIndexInfo>
Implementation of
moveBook()
moveBook(
__namedParameters):Promise<number>
Defined in: adapters/in-memory/InMemoryVectorIndexAdapter.ts:154
moveBook -- sets another library on every chunk of a book
About
Metadata only, the vectors stay.
Returns the number of chunks changed.
Who needs it
VectorStore.moveBook.
Parameters
__namedParameters
bookId
string
libraryId
string
tenantId
string
Returns
Promise<number>
Implementation of
search()
search(
__namedParameters):Promise<IChunkHit[]>
Defined in: adapters/in-memory/InMemoryVectorIndexAdapter.ts:117
search -- the k nearest chunks of a tenant
About
Best first, filtered by library, book, tags and language.
Only the tenant's records are searched; the filters are AND-ed as IChunkFilters says; the score is IChunkHit.score:
0..1, best 1.
Who needs it
VectorStore.search, for the KB retrieval.
Parameters
__namedParameters
filters
k
number
tenantId
string
vector
number[]
Returns
Promise<IChunkHit[]>
Implementation of
upsert()
upsert(
__namedParameters):Promise<void>
Defined in: adapters/in-memory/InMemoryVectorIndexAdapter.ts:53
upsert -- inserts or replaces chunk records
About
By chunk id within the tenant.
The store has checked tenant, model and dimensions already; the adapter writes.
Who needs it
VectorStore.upsertChunks, for the KB ingestion.
Parameters
__namedParameters
records
tenantId
string
Returns
Promise<void>