npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vector-cache-proxy

v1.0.1

Published

A vector-based semantic caching library with Redis for LLM responses

Downloads

13

Readme

Vector Cache Proxy

A semantic caching library using vector embeddings and Redis to cache LLM responses. Helps reduce costs and improve response times for similar queries.

Features

  • ✅ Uses vector embeddings for semantic search (no exact text match required)
  • ✅ Caches responses in Redis
  • ✅ Customizable similarity threshold
  • ✅ Multiple embedding model support
  • ✅ TypeScript support

Installation

# With npm
npm install vector-cache-proxy

# With Bun
bun add vector-cache-proxy

# With yarn
yarn add vector-cache-proxy

Requirements

  • Node.js >= 18 or Bun >= 1.0.0
  • Redis server

Usage

1. Initialize

import { VectorCacheProxy } from 'vector-cache-proxy';

const cacheProxy = new VectorCacheProxy({
  redis: {
    host: 'localhost',
    port: 6379,
    password: '', // optional
    db: 0, // optional
  },
  threshold: 0.85, // Similarity threshold (0-1), default: 0.85
  modelName: 'Xenova/all-MiniLM-L6-v2', // optional
});

// Initialize the model (required)
await cacheProxy.initialize();

2. API Methods

getEmbedding(text: string): Promise<number[]>

Convert text into vector embedding.

const embedding = await cacheProxy.getEmbedding('How to train a model?');
console.log(embedding); // [0.123, -0.456, ...]

setCache(text: string, response: any): Promise<void>

Store text query and response in cache.

const llmResponse = {
  answer: 'To train a model, you need data and...',
  tokens: 150,
  model: 'gpt-4',
};

await cacheProxy.setCache('How to train a model?', llmResponse);

getCache(text: string): Promise<any | null>

Search for cached response by semantic similarity. Returns null if not found.

// Similar query will return cached response
const cached = await cacheProxy.getCache('What is model training?');

if (cached) {
  console.log('✅ Cache hit:', cached);
} else {
  console.log('❌ Cache miss, calling LLM');
  // Call LLM and save to cache
  const response = await callLLM(text);
  await cacheProxy.setCache(text, response);
}

3. Complete Example with LLM

import { VectorCacheProxy } from 'vector-cache-proxy';

const cacheProxy = new VectorCacheProxy({
  redis: { host: 'localhost', port: 6379 },
  threshold: 0.85,
});

await cacheProxy.initialize();

async function askLLM(question: string) {
  // Check cache first
  const cached = await cacheProxy.getCache(question);

  if (cached) {
    console.log('✅ Using cache');
    return cached;
  }

  // Call LLM
  console.log('🔄 Calling LLM...');
  const response = await fetch('https://api.openai.com/v1/chat/completions', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
    },
    body: JSON.stringify({
      model: 'gpt-4',
      messages: [{ role: 'user', content: question }],
    }),
  });

  const data = await response.json();

  // Save to cache
  await cacheProxy.setCache(question, data);

  return data;
}

// Usage
const answer1 = await askLLM('How to train a model?');
const answer2 = await askLLM('What is model training?'); // ✅ Uses cache

await cacheProxy.close();

4. Additional Methods

clearCache(): Promise<void>

Clear all cached entries.

await cacheProxy.clearCache();

close(): Promise<void>

Close Redis connection.

await cacheProxy.close();

Configuration

VectorCacheProxyConfig

interface VectorCacheProxyConfig {
  redis: {
    host: string;        // Redis host
    port: number;        // Redis port
    username?: string;   // Redis username (optional)
    password?: string;   // Redis password (optional)
    db?: number;         // Redis database (optional, default: 0)
  };
  threshold?: number;    // Similarity threshold (0-1), default: 0.85
  modelName?: string;    // Embedding model, default: 'Xenova/all-MiniLM-L6-v2'
}

Threshold Guidelines

  • 0.95+: Very similar (nearly identical)
  • 0.85-0.95: Semantically similar (recommended)
  • 0.70-0.85: Related but may differ in meaning
  • < 0.70: Different

Supported Models

The library uses @xenova/transformers, you can choose different models:

  • Xenova/all-MiniLM-L6-v2 (default, 384 dimensions, fast)
  • Xenova/all-mpnet-base-v2 (768 dimensions, more accurate)
  • Xenova/paraphrase-multilingual-MiniLM-L12-v2 (better multilingual support)

License

MIT