@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.
Search
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
| Interface | Description |
|---|---|
| DeleteDocParams | Parameters for deleting a single document. |
| DeleteIndexParams | Parameters for deleting an index. |
| DeleteManyParams | Parameters for deleting multiple documents. |
| DeleteResult | Result of a delete operation. |
| DenseVector | Dense vector embedding. |
| DescribeIndexParams | Parameters for describing an index. |
| FieldOps | Field-level operators for filtering. |
| Filter | MongoDB-style filter expression. |
| FTSOptions | Full-text search options for a field. |
| GeoPoint | Geographic point. |
| IndexHandle | Handle to a specific index. |
| IndexStats | Statistics about an index. |
| IndexSummary | Summary of an index returned in list results. |
| ListIndexesParams | Parameters for listing indexes. |
| LogicalOps | Logical operators for combining filters. |
| NewIndexParams | Parameters for creating a new index. |
| OrderBy | Order by specification. |
| PatchResult | Result of a patch operation. |
| PlannedQuery | Result of planning a query against backend capabilities. |
| RankingSignal | A single ranking signal (text or vector query on a field). |
| ScalarFieldSchema | Schema for scalar/complex fields. |
| SearchCapabilities | Backend capabilities for query planning. |
| SearchHit | A search result hit. |
| SearchIndex | Generic search index interface. |
| SearchQuery | Full search query options. |
| SparseVector | Sparse vector (for hybrid/BM25 style search). |
| UpsertResult | Result of an upsert operation. |
| VectorFieldSchema | Schema for vector fields. |
Type Aliases
| Type Alias | Description |
|---|---|
| DocumentPatch | Document patch - partial update with null to unset fields. |
| FieldSchema | Field schema - either scalar or vector. |
| FieldValue | Field value - the actual data stored in a field. |
| QueryInput | Query input - flexible format supporting multiple patterns. |
| ScalarValue | - |
| SearchFieldType | Supported field types in a search schema. |
| SearchMode | Supported search modes. |
| UnknownDocument | - |
Functions
| Function | Description |
|---|---|
| embed | Embed a single text value. |
| embedMany | Embed multiple text values. |
| isHybridQuery | Check if query input is an array (hybrid sum fusion). |
| isQueryOptions | Check if query input is a full query options object. |
| isSimpleQuery | Check if query input is a simple single-field query. |
| normalizeQuery | Normalize query input to full QueryOptions. |
| planQuery | Plan a query against backend capabilities. |
| registerEmbeddingProvider | Register an embedding provider. Typically called automatically when importing provider packages. |
| resolveEmbeddingModel | Resolve an embedding model from a provider/model-id string. |