01Install
Install from npm into your project.
BASH
pnpm add @lov3kaizen/agentsea-embeddings02Example
TS
import { createEmbeddingManager, createOpenAIProvider } from '@lov3kaizen/agentsea-embeddings';
const provider = createOpenAIProvider({
type: 'openai',
apiKey: process.env.OPENAI_API_KEY!,
model: 'text-embedding-3-small',
});
const manager = createEmbeddingManager({ defaultModel: 'text-embedding-3-small', defaultProvider: 'openai' });
manager.registerModel(provider, true);
const result = await manager.embed('Hello, world!');
console.log('Dimensions:', result.dimensions);03Key API
createEmbeddingManager(options)Creates a manager that holds models, a cache and a store.
manager.embed(text) / embedBatch(texts) / embedDocument(text)Creates embeddings for text. embedDocument splits the text with the chunker set by setChunker.
manager.search(query, { topK, minScore })Finds stored vectors that are close to a query.
createOpenAIProvider({ type: 'openai', apiKey, model, dimensions })Creates an OpenAI embedding provider. createCohereProvider, createVoyageProvider and createHuggingFaceProvider follow the same pattern.
createRecursiveChunker() / createMarkdownChunker() / createCodeChunker()Splits documents into chunks before embedding. These factories take no options in this version.
04Caveats
- createMemoryStore takes type: 'memory' and a dimensions value.
- setCache and setStore are typed to the EmbeddingCache and EmbeddingStore interfaces. The results of createMemoryCache and createMemoryStore do not match those types as written in this version, so the README Quick Start does not compile as shown. The example above leaves them out.
- createLocalProvider and createSemanticChunker need an embedding function you supply. The examples use placeholders.
- The Redis cache needs await cache.connect(), and the SQLite cache needs await cache.init(). Each store needs await store.init().
- DriftDetector and createDriftDetector are exported. This page does not cover them.
05Providers and chunkers
createOpenAIProvider(config)OpenAI embeddings.
createCohereProvider(config)Cohere embeddings.
createVoyageProvider(config)Voyage AI embeddings.
createHuggingFaceProvider(config)HuggingFace embeddings.
createLocalProvider(config)A provider that wraps your own embedding function.
createRecursiveChunker() / createMarkdownChunker() / createCodeChunker()Chunkers for plain text, Markdown and source code.
createSemanticChunker()Chunks by meaning. It needs an embedding function.
06Caches and stores
createMemoryCache(options?) / createRedisCache / createSQLiteCache / createTieredCacheCaches for embedding results. Use the memory cache for development, and Redis or SQLite to share or keep results.
createMemoryStore(config?)An in-memory vector store, with optional persistence to a file.
createPineconeStore / createChromaStore / createQdrantStore / createPgVectorStore / createWeaviateStore / createMilvusStoreVector stores for hosted and self-hosted databases. Each one needs its own client and credentials.