kernl

Interface: IndexHandle<TDocument>

Defined in: retrieval/src/handle.ts:50

Handle to a specific index.

Type Parameters

Type ParameterDefault typeDescription
TDocumentUnknownDocumentShape of the document fields. Defaults to UnknownDocument. Obtained via SearchIndex.index(id).

Properties

PropertyModifierTypeDefined in
idreadonlystringretrieval/src/handle.ts:51

Methods

addField()

addField(field: string, schema: FieldSchema): Promise<void>;

Defined in: retrieval/src/handle.ts:131

Add a field to the index schema.

Not all backends support schema mutation. Throws if unsupported.

Parameters

ParameterType
fieldstring
schemaFieldSchema

Returns

Promise<void>


delete()

delete(ids: string | string[]): Promise<DeleteResult>;

Defined in: retrieval/src/handle.ts:93

Delete one or more documents by ID.

Parameters

ParameterType
idsstring | string[]

Returns

Promise<DeleteResult>


patch()

patch(patches: 
  | DocumentPatch<TDocument>
| DocumentPatch<TDocument>[]): Promise<PatchResult>;

Defined in: retrieval/src/handle.ts:86

Patch one or more documents.

Only specified fields are updated. Set a field to null to unset it.

Parameters

ParameterType
patches| DocumentPatch<TDocument> | DocumentPatch<TDocument>[]

Returns

Promise<PatchResult>

Example

// update title only
await index.patch({ id: "doc-1", title: "New Title" });

// unset a field
await index.patch({ id: "doc-1", description: null });

query()

query(query: QueryInput): Promise<SearchHit<TDocument>[]>;

Defined in: retrieval/src/handle.ts:122

Query the index.

Parameters

ParameterType
queryQueryInput

Returns

Promise<SearchHit<TDocument>[]>

Example

// simple text search
await index.query({ content: "quick fox" });

// vector search
await index.query({ embedding: [0.1, 0.2, ...] });

// hybrid sum fusion
await index.query([
  { content: "quick fox", weight: 0.7 },
  { embedding: [...], weight: 0.3 },
]);

// with filter
await index.query({
  query: [{ content: "fox" }],
  filter: { published: true },
  limit: 20,
});

upsert()

upsert(docs: TDocument | TDocument[]): Promise<UpsertResult>;

Defined in: retrieval/src/handle.ts:70

Upsert one or more documents.

Documents are flat objects. The adapter determines which field is the primary key (typically id by convention).

Parameters

ParameterType
docsTDocument | TDocument[]

Returns

Promise<UpsertResult>

Example

await index.upsert({ id: "doc-1", title: "Hello", embedding: [0.1, ...] });
await index.upsert([
  { id: "doc-1", title: "Hello" },
  { id: "doc-2", title: "World" },
]);

On this page