Skip to main content

Class: LibraryIndex

Defined in: packages/agentos/src/cognition/library/LibraryIndex.ts:188

A library's sources in one collection of a vector store. Every passage of a source carries the source's tenant, access groups, kind, folder, tags and title in its metadata, so the store's own filter selects who sees it and the index checks what the store answers: indexSource replaces a source whole, setSourceScope changes who may see it and where it is filed, removeSource and removeTenant delete, and search reads only what its scope may see.

Constructors​

Constructor​

new LibraryIndex(options): LibraryIndex

Defined in: packages/agentos/src/cognition/library/LibraryIndex.ts:195

An index over a collection the store already holds; the index makes no collection.

Parameters​

options​

LibraryIndexOptions

Returns​

LibraryIndex

Methods​

indexSource()​

indexSource(source): Promise<{ passages: number; }>

Defined in: packages/agentos/src/cognition/library/LibraryIndex.ts:208

Indexes a source, replacing whatever the collection held under its id: the old passages are deleted first, then the new ones are embedded and written batchSize at a time. A failed batch leaves the passages written before it, and indexing the source again replaces them. A delete or a write the store reports as failed in its result, instead of throwing, fails the call as well.

Parameters​

source​

LibrarySource

Returns​

Promise<{ passages: number; }>


removeSource()​

removeSource(sourceId): Promise<number>

Defined in: packages/agentos/src/cognition/library/LibraryIndex.ts:244

Removes a source's passages and answers the store's deletedCount: how many went on a store that counts a delete by filter, as PostgresVectorStore and InMemoryVectorStore do, and the store's own value on one that does not (-1 on PineconeVectorStore, 0 on QdrantVectorStore). Throws when the store reports the delete as failed.

Parameters​

sourceId​

string

Returns​

Promise<number>


removeTenant()​

removeTenant(tenantId): Promise<number>

Defined in: packages/agentos/src/cognition/library/LibraryIndex.ts:254

Removes every passage of one tenant and answers the store's deletedCount, as removeSource does. Throws when the store reports the delete as failed.

Parameters​

tenantId​

string

Returns​

Promise<number>


search(query): Promise<LibraryPassage[]>

Defined in: packages/agentos/src/cognition/library/LibraryIndex.ts:284

Searches what the scope may see. The store's filter selects the passages, and the index keeps only those whose metadata meets the scope and the narrowing: a store whose filter drops or ignores a condition cannot widen the answer, which can then hold fewer than topK passages. With anyOf, each narrowing is searched leg by leg under the same scope and the answers are ranked as one search's (LibrarySearch.anyOf).

Parameters​

query​

LibrarySearch

Returns​

Promise<LibraryPassage[]>


setSourceScope()​

setSourceScope(sourceId, change): Promise<number>

Defined in: packages/agentos/src/cognition/library/LibraryIndex.ts:261

Changes who may see a source, its folder, its tags or its title; folderId: null takes it out of its folder.

Parameters​

sourceId​

string

change​
aclGroups?​

string[]

folderId?​

string | null

tags?​

string[]

title?​

string

Returns​

Promise<number>