Vercel AI SDK¶
Package: @holographic-memory/vercel-ai (peer: ai >=7 <8, zod). Built on @holographic-memory/core (see js-core.md).
The AI SDK has no vector-store or memory abstraction of its own: its memory guide lists provider-defined tools, hosted memory providers and custom tools. This package is the custom-tool path plus the SDK's documented RAG middleware pattern, so it works with any model provider.
import { ToolLoopAgent, wrapLanguageModel } from 'ai'
import { HmsStore } from '@holographic-memory/core'
import { memoryMiddleware, memoryTools } from '@holographic-memory/vercel-ai'
const store = new HmsStore({ path: './memory' })
const agent = new ToolLoopAgent({
model: wrapLanguageModel({ model: yourModel, middleware: memoryMiddleware(store, { k: 3, scope: { userId } }) }),
tools: memoryTools(store, { scope: { userId } }),
})
Exports¶
memoryTools(store, {scope, k, names, readOnly}):remember,recall,forgetas AI SDKtool()s withinputSchema(zod).scopemetadata is merged into every remembered record and ANDed into every recall;forgetonly deletes records inside the scope. Tool inputs are validated by the SDK; a bad call surfaces as atool-errorpart and never reaches the store.metadataandfilterinputs are flat string/number/boolean maps (equality filters, evaluated by the engine before ranking).memoryMiddleware(store, {k, filter, scope, minSemanticScore, maxChars, format, queryFrom}): aLanguageModelV4MiddlewarewhosetransformParamsrecalls for the last user message and appends the memories as an extra text part of that message. Works forgenerateText,streamTextand agents. Stored message history is not modified.aiSdkEmbedder(embeddingModel, {model, revision, dimensions}): any AI SDK embedding model as the store's encoder (usesembed/embedMany).aiSdkReranker(rerankingModel): any AI SDK reranking model as the store'srerankhook (usesrerank).
HMS knobs (BM25 k1/b, titleWeight, lexical/semantic weights, fusion, encryption through hmsConfig, collection) are options of HmsStore; the adapter adds none of its own.
Limits¶
- Filters follow the core rules: tool filters are equality only;
memoryMiddleware({filter})accepts the full core filter syntax, with client-side terms evaluated onoverfetch * kcandidates. minSemanticScoreis a cosine threshold; the default hashing embedder is lexical, so thresholds are only meaningful with a semantic embedder.- The middleware adds one
recall(one embedding call if the encoder is remote) per model call, including each step of a tool loop. - Verified against the v4 language model specification only (
specificationVersion: 'v4').
Tested against¶
ai 7.0.146, zod 4.1.x, Node 26.8. Tests (npm test --workspace packages/vercel-ai) use the SDK's own MockLanguageModelV4, MockEmbeddingModelV4 and MockRerankingModelV4 from ai/test, a real tool loop (generateText with isStepCount), streamText, and the real native engine. examples/agent.mjs runs a ToolLoopAgent with both pieces offline.