@zukhruf/embedding-cache has 34,414 recorded weekly downloads on npm, a change of +7.0% over the past 7 days, ranking #889 of 3,247 tracked listings.
About @zukhruf/embedding-cache
@zukhruf/embedding-cache
Ezz accepted each ADR on 2026-11-19.
A model call is the slow and paid part of an embedding. This package wraps an AI SDK embedding model so that each embed and embedMany call through it calls the model only for text that it did not embed before. A hit gives back exactly the numbers that the model gave the first time.
The words in these documents have one meaning each. See the glossary in CONTEXT.md.
Use it
npm install @zukhruf/embedding-cache ai
import { embedMany, wrapEmbeddingModel } from 'ai';
import { embeddingCacheMiddleware } from '@zukhruf/embedding-cache';
import { SqliteEmbeddingCacheStore } from '@zukhruf/embedding-cache/sqlite';
SqliteEmbeddingCacheStore.declaration('embedding_cache').apply(database, {
rows: 'keep',
});
const model = wrapEmbeddingModel({
model: openai.embedding('text-embedding-3-small'),
middleware: embeddingCacheMiddleware({
store: new SqliteEmbeddingCacheStore({
database,
table: 'embedding_cache',
}),
}),
});
const { embeddings } = await embedMany({ model, values: texts });
// Only the texts that the store does not hold reach OpenAI.
A model with other prompts for documents and for queries is two wrapped models with two model ids; their keys never meet (ADR 0003).
Keep the cache in SQL Server
import { SqlServerEmbeddingCacheStore } from '@zukhruf/embedding-cache/sqlserver';
import type { SqlServerSession } from '@zukhruf/schema-drift/sqlserver';
// The session of schema-drift: queries on the pool, and a transaction of
// mssql.Transaction for apply. The store takes it too, and sends only queries.
const session: SqlServerSession = {
async query(sql, parameters) {
const request = pool.request();
for (const [name, value] of Object.entries(parameters))
request.input(name, value);
return (await request.query(sql)).recordset ?? [];
},
async transaction(work) {
const transaction = new mssql.Transaction(pool);
await transaction.begin();
try {
const inner: SqlServerSession = {
async query(sql, parameters) {
const request = new mssql.Request(transaction);
for (const [name, value] of Object.entries(parameters))
request.input(name, value);
return (await request.query(sql)).recordset ?? [];
},
transaction: async (nested) => nested(inner),
};
await work(inner);
await transaction.commit();
} catch (error) {
await transaction.rollback();
throw error;
}
},
};
await SqlServerEmbeddingCacheStore.declaration('dbo.embedding_cache').apply(
session,
{ rows: 'keep' },
);
const store = await SqlServerEmbeddingCacheStore.open({
session,
table: 'dbo.embedding_cache',
});
The session is the one that @zukhruf/schema-drift takes, so apply has its transaction. The store takes the same object and sends only query. open takes a signal too, and gives it to each query of its check.
Apply the table before a store opens
Each SQL store keeps one table, and exports its declaration, a declaration of @zukhruf/schema-drift. The host applies it, at deploy, at start or from its own tool. The store only checks it when it opens, and runs no DDL (ADR 0006).
SqliteEmbeddingCacheStore.declaration(table)is aSqliteDeclaration. The table name is one identifier, with no schema.SqlServerEmbeddingCacheStore.declaration(table)is aSqlServerDeclaration. The table name is a schema and a name,dbo.embedding_cache, and the ledger of schema-drift goes in that schema. The host makes the schema: the declaration does not declare it. Its schema-driftnameholds the table,@zukhruf/embedding-cache/sqlserver:dbo.embedding_cache, so two caches in one schema own their tables apart, and the apply of one never drops the other's.rowsis the host's choice. Give'keep': a vector is a paid model call, and a cache with no rows calls the model again for each text.new SqliteEmbeddingCacheStore({ database, table })andSqlServerEmbeddingCacheStore.openthrowSchemaDriftErrorof@zukhruf/schema-driftwhen the table is missing or stale. Itsobjectsnames the table. The next step is the host's: apply the declaration.- A SQLite table that an earlier version of the store made fits the declaration. A SQL Server table that an earlier version made has no ledger row, so
opennames it as stale. Apply once withrows: 'keep': the vectors stay.
What a call does underneath…
Description from the npm listing.
- embedding
- cache
- ai-sdk
- middleware
- sqlite
- sql-server
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (128)Similar npm AI SDKs plugins
All 20 @zukhruf/embedding-cache alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/@zukhruf/embedding-cache. First seen Nov 23, 2026; last successful collection Dec 6, 2026. See the methodology.