JavaScript: Vectors and embeddings
Turn text into embeddings, store vectors with metadata and run similarity search with @sovaria/sdk.
sovaria.vector stores embeddings in collections and finds the nearest ones to a query — the building block for semantic search and retrieval-augmented generation.
await sovaria.vector.upsert('articles', [
{ id: 'a1', text: 'How to reset your password', metadata: { lang: 'en' } },
{ id: 'a2', text: 'Exporting invoices as PDF', metadata: { lang: 'en' } },
])
const hits = await sovaria.vector.search('articles', 'forgot my login', { topK: 3, metadataFilter: { lang: 'en' } })sovaria.vector
sovaria.vector.embed
Embed.
sovaria.vector.embed(
texts: string[],
): Promise<{ vectors: number[][]; dim: number; count: number; }>Parameters
textsstring[]required- Texts to embed.
- Returns
Promise<{ vectors: number[][]; dim: number; count: number; }>—{ vectors }— one array of numbers per text.- HTTP
POST /api/v1/embed
sovaria.vector.upsert
Upsert.
sovaria.vector.upsert(
collection: string,
docs: Array<{ id?: string; text: string; metadata?: JsonObject }>,
): Promise<JsonObject>Parameters
collectionstringrequired- Collection name.
docsArray<{ id?: string; text: string; metadata?: JsonObject }>required[{ id?, text, metadata? }]; texts are embedded for you.
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/vectors/upsert
sovaria.vector.search
Search.
sovaria.vector.search(
collection: string,
query: string,
options?: { topK?: number; metadataFilter?: JsonObject } = {},
): Promise<JsonObject>Parameters
collectionstringrequired- Collection name.
querystringrequired- Text to search for.
options{ topK?: number; metadataFilter?: JsonObject }optionaldefault{}topK(how many),metadataFilter(exact matches on metadata).
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/vectors/search
sovaria.vector.listCollections
List collections.
sovaria.vector.listCollections(): Promise<JsonObject>- Returns
Promise<JsonObject>- HTTP
GET /api/v1/collections
sovaria.vector.listRecords
List records.
sovaria.vector.listRecords(
collection: string,
options?: { limit?: number; offset?: number } = {},
): Promise<JsonObject>Parameters
collectionstringrequiredoptions{ limit?: number; offset?: number }optionaldefault{}
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/collections/{…}/records
sovaria.vector.deleteRecord
Delete record.
sovaria.vector.deleteRecord(collection: string, recordId: string): Promise<JsonObject>Parameters
collectionstringrequiredrecordIdstringrequired
- Returns
Promise<JsonObject>- HTTP
DELETE /api/v1/collections/{…}/records/{…}
sovaria.vector.deleteCollection
Delete collection.
sovaria.vector.deleteCollection(collection: string): Promise<JsonObject>Parameters
collectionstringrequired
- Returns
Promise<JsonObject>- HTTP
DELETE /api/v1/collections/{…}
Something unclear or missing on this page?Tell us