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

@ai_kit/rag

v0.1.0-alpha-03

Published

RAG abstraction layer for AI Kit (documents, chunking, embeddings, vector stores).

Downloads

266

Readme

@ai_kit/rag

Couche RAG DX-first pour AI Kit : document helpers, chunking récursif, embeddings via AI SDK et connecteurs de vector store (mémoire et pgvector). Permet d’ingérer, requêter et générer une réponse en quelques lignes.

import { createRag, RagDocument, MemoryVectorStore } from "@ai_kit/rag";
import { openai } from "@ai-sdk/openai";

const rag = createRag({
  embedder: openai.embedding("text-embedding-3-small"),
  store: new MemoryVectorStore(),
  chunker: { size: 512, overlap: 50 },
});

const doc = RagDocument.fromText("Your document text here...");
await rag.ingest({ namespace: "kb", documents: [doc] });

const results = await rag.search({ namespace: "kb", query: "What is inside?" });
const answer = await rag.answer({
  namespace: "kb",
  query: "What is inside?",
  model: openai("gpt-4o-mini"),
});

Principales briques

  • RagDocument.fromText/fromJSON/fromFile : normalise un document avec id stable + métadonnées.
  • Chunking récursif via splitTextRecursively de @ai_kit/core (options size, overlap, separators).
  • Embedder générique (fonction ou EmbeddingModel du SDK ai).
  • Vector stores : MemoryVectorStore (tests/démos) et PgVectorStore (pgvector, imports dynamiques).
  • ingest (chunk → embed → upsert), search (embed query → vector store), answer (search → prompt RAG avec placeholders {query}/{context} + streaming via answer.stream).

Voir package-rag.md pour le design détaillé et la roadmap.

Utiliser Postgres + pgvector

Pré-requis :

  • Extensions installées sur votre base : CREATE EXTENSION IF NOT EXISTS vector;
  • Dépendances côté projet : pnpm add pg pgvector @ai_kit/rag @ai-sdk/openai
  • Variable d’environnement : POSTGRES_CONNECTION_STRING=postgres://user:password@host:5432/db

Exemple :

import { createRag, RagDocument, PgVectorStore } from "@ai_kit/rag";
import { openai } from "@ai-sdk/openai";

const rag = createRag({
  embedder: openai.embedding("text-embedding-3-small"),
  store: new PgVectorStore({
    connectionString: process.env.POSTGRES_CONNECTION_STRING!,
    // options: tableName, schema, indexName, dimensions, pool
  }),
  chunker: { size: 512, overlap: 50 },
});

await rag.ingest({
  namespace: "kb",
  documents: [RagDocument.fromText("Paris est la capitale de la France")],
});

// Requête RAG : recherche seule
const results = await rag.search({
  namespace: "kb",
  query: "Quelle est la capitale de la France ?",
  topK: 3,
});

console.log(results.map((r) => ({ score: r.score, text: r.chunk.text })));

// Ou génération complète
const answer = await rag.answer({
  namespace: "kb",
  query: "Quelle est la capitale de la France ?",
  model: openai("gpt-4o-mini"),
});

console.log(answer.text);

Notes :

  • Le store crée le schéma/table/index IVFFLAT au démarrage si besoin (rag_vectors par défaut). Pensez à ANALYZE si vous venez de peupler la table pour de meilleures perfs.
  • upsertMode: "replace" dans ingest supprime le namespace avant réinsertion (si votre Postgres autorise DELETE).
  • Le connecteur utilise cosine distance (vector_cosine_ops). Ajustez dimensions si votre modèle ne correspond pas à la taille par défaut détectée par pgvector.