New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@betterdb/ai

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@betterdb/ai

One install for the BetterDB AI stack on Valkey: agent cache, semantic cache, retrieval, agent memory, and search helpers

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

@betterdb/ai

One install for the BetterDB AI stack on Valkey.

npm install @betterdb/ai iovalkey

Usage

import Valkey from 'iovalkey';
import { AgentCache, SemanticCache, MemoryStore, Retriever } from '@betterdb/ai';

const client = new Valkey({ host: 'localhost', port: 6379 });
const cache = new AgentCache({ client });

Framework adapters

ImportProvides
@betterdb/ai/langchainBetterDBLlmCache, BetterDBSemanticCache
@betterdb/ai/langgraphBetterDBSaver, BetterDBSemanticStore
@betterdb/ai/vercelcreateAgentCacheMiddleware, createSemanticCacheMiddleware
@betterdb/ai/openaiprepareParams, prepareSemanticParams
@betterdb/ai/openai-responsesprepareParams, prepareSemanticParams
@betterdb/ai/anthropicprepareParams, prepareSemanticParams
@betterdb/ai/llamaindexprepareParams, prepareSemanticParams

Install the matching framework yourself. Six framework peers are optional (/openai and /openai-responses both use the openai peer) — iovalkey is the seventh peer and is required.

Subpath imports (everything but the root @betterdb/ai import) require "moduleResolution" set to "node16", "nodenext", or "bundler" in your tsconfig.json. The root import works under classic "node" resolution too.

Embedding functions

SemanticCache requires an embedFn to turn text into a vector. Bring your own, or use one of these provider-backed factories:

ImportProvides
@betterdb/ai/embed/openaicreateOpenAIEmbed
@betterdb/ai/embed/bedrockcreateBedrockEmbed
@betterdb/ai/embed/voyagecreateVoyageEmbed
@betterdb/ai/embed/coherecreateCohereEmbed
@betterdb/ai/embed/ollamacreateOllamaEmbed
@betterdb/ai/embed/googlecreateGoogleEmbed
import { SemanticCache } from '@betterdb/ai';
import { createOpenAIEmbed } from '@betterdb/ai/embed/openai';

const cache = new SemanticCache({ client, embedFn: createOpenAIEmbed() });

Namespaces

A handful of names are declared by more than one underlying package, so they are not exported flat. Reach them through the namespace for the package you want:

import Valkey from 'iovalkey';
import { AgentCache, agentCache, semanticCache } from '@betterdb/ai';

const cache = new AgentCache({ client: new Valkey() });

try {
  await cache.llm.check({
    model: 'claude-sonnet-4-5',
    messages: [{ role: 'user', content: 'hello' }],
  });
} catch (err) {
  if (err instanceof agentCache.ValkeyCommandError) {
    // agent-cache errors extend AgentCacheError
  } else if (err instanceof semanticCache.ValkeyCommandError) {
    // semantic-cache's ValkeyCommandError extends Error — a different class
    // that happens to share the name
  }
}

const block: agentCache.ContentBlock = { type: 'text', text: 'hello' };

Namespaces: agentCache, semanticCache, retrieval, memory, searchKit. Each mirrors the corresponding package's full root export surface, so anything not available flat is available here.

Relationship to the individual packages

@betterdb/ai re-exports, and pins exact versions of:

  • @betterdb/agent-cache — multi-tier exact-match cache
  • @betterdb/semantic-cache — embedding-similarity cache
  • @betterdb/retrieval — vector + filtered query over valkey-search
  • @betterdb/agent-memory — short-term tiers plus semantic long-term memory
  • @betterdb/valkey-search-kit — shared FT.* helpers

They remain published and supported. Install them directly if you want a narrower dependency; install @betterdb/ai if you want the whole stack at one mutually-compatible set of versions.

Versioning

Facade releases are automatic patch bumps triggered by each child's own release, and may carry breaking changes from a child package. Consumers who need strict semver guarantees should pin @betterdb/ai to an exact version.

Keywords

valkey

FAQs

Package last updated on 31 Aug 2026

Related posts