kernl

@kernl-sdk/retrieval

For AI agents: These reference docs help coding agents understand the kernl SDK. If your agent gets stuck, share this page with it.

Generic search and retrieval abstractions for kernl.

Provider-agnostic interface for text + vector search:

import type { SearchIndex, IndexHandle } from '@kernl-sdk/retrieval';

// -- index lifecycle --
await search.createIndex({ id: 'docs', dimensions: 1536 });
const docs: IndexHandle = search.index('docs');

// query with vectors + text
const hits = await docs.query({
  query: [{ text: 'search query', tvec: [0.1, 0.2, ...] }],
  filter: { category: 'technical' },
  limit: 10,
});

// upsert documents
await docs.upsert({ id: '1', text: 'content', tvec: [...] });

Embeddings

Simple text embedding with auto-registered providers:

import { embed, embedMany } from '@kernl-sdk/retrieval';
import { openai } from '@kernl-sdk/ai/openai';

// single text
const { embedding } = await embed({
  model: 'openai/text-embedding-3-small',
  text: 'sunny day at the beach',
});

// multiple texts
const { embeddings } = await embedMany({
  model: 'openai/text-embedding-3-small',
  texts: ['hello', 'world'],
});

Supported Providers

  • OpenAI: import { openai } from '@kernl-sdk/ai/openai'
  • Google: import { google } from '@kernl-sdk/ai/google'

Interfaces

InterfaceDescription
DeleteDocParamsParameters for deleting a single document.
DeleteIndexParamsParameters for deleting an index.
DeleteManyParamsParameters for deleting multiple documents.
DeleteResultResult of a delete operation.
DenseVectorDense vector embedding.
DescribeIndexParamsParameters for describing an index.
FieldOpsField-level operators for filtering.
FilterMongoDB-style filter expression.
FTSOptionsFull-text search options for a field.
GeoPointGeographic point.
IndexHandleHandle to a specific index.
IndexStatsStatistics about an index.
IndexSummarySummary of an index returned in list results.
ListIndexesParamsParameters for listing indexes.
LogicalOpsLogical operators for combining filters.
NewIndexParamsParameters for creating a new index.
OrderByOrder by specification.
PatchResultResult of a patch operation.
PlannedQueryResult of planning a query against backend capabilities.
RankingSignalA single ranking signal (text or vector query on a field).
ScalarFieldSchemaSchema for scalar/complex fields.
SearchCapabilitiesBackend capabilities for query planning.
SearchHitA search result hit.
SearchIndexGeneric search index interface.
SearchQueryFull search query options.
SparseVectorSparse vector (for hybrid/BM25 style search).
UpsertResultResult of an upsert operation.
VectorFieldSchemaSchema for vector fields.

Type Aliases

Type AliasDescription
DocumentPatchDocument patch - partial update with null to unset fields.
FieldSchemaField schema - either scalar or vector.
FieldValueField value - the actual data stored in a field.
QueryInputQuery input - flexible format supporting multiple patterns.
ScalarValue-
SearchFieldTypeSupported field types in a search schema.
SearchModeSupported search modes.
UnknownDocument-

Functions

FunctionDescription
embedEmbed a single text value.
embedManyEmbed multiple text values.
isHybridQueryCheck if query input is an array (hybrid sum fusion).
isQueryOptionsCheck if query input is a full query options object.
isSimpleQueryCheck if query input is a simple single-field query.
normalizeQueryNormalize query input to full QueryOptions.
planQueryPlan a query against backend capabilities.
registerEmbeddingProviderRegister an embedding provider. Typically called automatically when importing provider packages.
resolveEmbeddingModelResolve an embedding model from a provider/model-id string.

On this page