スキル一覧に戻る
BetterStacks

unrag

by BetterStacks

Unrag is a RAG installer that adds small, auditable, drop-in primitives for ingest/retrieve and adapters directly into your codebase as vendored source files.

13🍴 0📅 2026年1月21日
GitHubで見るManusで実行

SKILL.md


name: unrag description: Covers RAG installation, ContextEngine API, embedding providers, store adapters, extractors, connectors, batteries, and CLI commands for the unrag TypeScript library. version: 0.3.2

Unrag Agent Skill

This skill provides comprehensive knowledge about unrag - a RAG (Retrieval-Augmented Generation) installer for TypeScript that vendors auditable source code directly into your project.

What is Unrag

Unrag takes a deliberately different approach to RAG: instead of being a framework or SDK, it vendors source files directly into your repository. When you run unrag init, you're not adding a dependency that abstracts away the implementation—you're copying source files that are yours to read, modify, and delete.

Philosophy

  • You own your RAG implementation - The code lives in your repo, appears in PRs, and can be debugged like any other code
  • Primitives over frameworks - Unrag gives you ingest() and retrieve(), not routing, agents, or prompt templates
  • Swappable components - Simple interfaces for embedding providers, store adapters, and extractors
  • Local-first development - No external services, just code in your codebase

Core Operations

  1. ingest() - Chunk content, generate embeddings, store in Postgres with pgvector
  2. retrieve() - Embed a query and run similarity search
  3. rerank() - Optional second-stage ranking for improved precision
  4. delete() - Remove documents by sourceId or prefix

Quick Start

Installation

# Initialize unrag in your project
bunx unrag@latest init

# Follow prompts to select:
# - Install directory (default: lib/unrag)
# - Store adapter (Drizzle, Prisma, or Raw SQL)
# - Embedding provider (OpenAI, Google, Cohere, etc.)
# - Rich media extractors (PDF, images, etc.)

Minimal Configuration

// unrag.config.ts
import { defineUnragConfig } from "./lib/unrag/core";

export const unrag = defineUnragConfig({
  embedding: {
    provider: "openai",
    config: {
      model: "text-embedding-3-small",
    },
  },
} as const);

First Ingest

import { createUnragEngine } from "@unrag/config";

const engine = createUnragEngine();

await engine.ingest({
  sourceId: "docs:getting-started",
  content: "Your document content here...",
  metadata: { title: "Getting Started", category: "docs" },
});

First Retrieval

const result = await engine.retrieve({
  query: "how do I get started?",
  topK: 8,
});

for (const chunk of result.chunks) {
  console.log(chunk.content, chunk.score);
}

Core Concepts

ContextEngine

The ContextEngine class is the main entry point. Create it using createUnragEngine() which reads from unrag.config.ts:

import { createUnragEngine } from "@unrag/config";

const engine = createUnragEngine();

The engine provides:

  • engine.ingest(input) - Ingest documents with optional assets
  • engine.retrieve(input) - Query for relevant chunks
  • engine.rerank(input) - Rerank retrieved candidates
  • engine.delete(input) - Delete by sourceId or prefix
  • engine.planIngest(input) - Dry-run for asset processing
  • engine.runConnectorStream(options) - Process connector streams

Source ID Scoping

The sourceId is a stable identifier for your documents:

// Single document
await engine.ingest({ sourceId: "doc:123", content: "..." });

// Hierarchical organization
await engine.ingest({ sourceId: "tenant:acme:docs:readme", content: "..." });

// Retrieve with prefix scope
const result = await engine.retrieve({
  query: "password reset",
  scope: { sourceId: "tenant:acme:" },  // Only this tenant's docs
});

Key behaviors:

  • Re-ingesting with the same sourceId replaces the previous version
  • Delete supports both exact match and prefix deletion
  • Retrieval scope uses prefix matching

Chunking

Documents are split into chunks before embedding:

// Global defaults in unrag.config.ts
export const unrag = defineUnragConfig({
  defaults: {
    chunking: {
      chunkSize: 512,    // tokens per chunk
      chunkOverlap: 50,  // overlap between chunks
    },
  },
  // ...
});

// Per-ingest override
await engine.ingest({
  sourceId: "doc:123",
  content: longDocument,
  chunking: { chunkSize: 256 },
});

Asset Processing

Rich media (PDFs, images, audio, video, files) can be attached to documents:

await engine.ingest({
  sourceId: "doc:report",
  content: "Quarterly report summary...",
  assets: [
    {
      assetId: "attachment-1",
      kind: "pdf",
      data: { kind: "bytes", bytes: pdfBuffer, mediaType: "application/pdf" },
    },
  ],
});

Assets are processed by extractors that convert them to text for embedding. See extractors.md.

API Quick Reference

ingest()

const result = await engine.ingest({
  sourceId: string,           // Stable document identifier
  content: string,            // Document text
  metadata?: Metadata,        // Optional key-value pairs
  chunking?: { chunkSize?, chunkOverlap? },
  assets?: AssetInput[],      // Optional rich media
  assetProcessing?: DeepPartial<AssetProcessingConfig>,
});

// Returns:
// { documentId, chunkCount, embeddingModel, warnings, durations }

retrieve()

const result = await engine.retrieve({
  query: string,              // Search query
  topK?: number,              // Number of results (default: 8)
  scope?: { sourceId?: string },  // Prefix filter
});

// Returns:
// { chunks: Array<Chunk & { score }>, embeddingModel, durations }

rerank()

const result = await engine.rerank({
  query: string,
  candidates: RerankCandidate[],  // From retrieve()
  topK?: number,
  onMissingReranker?: "throw" | "skip",
  onMissingText?: "throw" | "skip",
  resolveText?: (candidate) => string | Promise<string>,
});

// Returns:
// { chunks, ranking, meta, durations, warnings }

delete()

// Delete single document
await engine.delete({ sourceId: "doc:123" });

// Delete by prefix
await engine.delete({ sourceIdPrefix: "tenant:acme:" });

planIngest()

Dry-run to preview asset processing without calling external services:

const plan = await engine.planIngest({
  sourceId: "doc:report",
  content: "...",
  assets: [/* ... */],
});

// Returns which assets would be processed, by which extractors

runConnectorStream()

Process events from a connector:

const stream = notionConnector.sync({ pageIds: ["..."] });

const result = await engine.runConnectorStream({
  stream,
  onProgress: (event) => console.log(event),
});

Configuration

defineUnragConfig()

The main configuration function:

import { defineUnragConfig } from "./lib/unrag/core";

export const unrag = defineUnragConfig({
  // Embedding provider configuration (required)
  embedding: {
    provider: "openai",
    config: { model: "text-embedding-3-small" },
  },

  // Default settings
  defaults: {
    chunking: { chunkSize: 512, chunkOverlap: 50 },
    embedding: { concurrency: 4, batchSize: 100 },
    retrieval: { topK: 8 },
  },

  // Engine-level configuration
  engine: {
    extractors: [/* ... */],      // Asset extractors
    reranker: createCohereReranker(),
    storage: {
      storeChunkContent: true,
      storeDocumentContent: true,
    },
    assetProcessing: {/* ... */},
  },
} as const);

Environment Variables

Common environment variables by provider:

ProviderVariables
OpenAIOPENAI_API_KEY
GoogleGOOGLE_GENERATIVE_AI_API_KEY
CohereCOHERE_API_KEY
AzureAZURE_OPENAI_API_KEY, AZURE_RESOURCE_NAME
VoyageVOYAGE_API_KEY
Ollama(none, runs locally)

Database: DATABASE_URL

Reference File Guide

This skill includes detailed reference files for specific topics:

ReferenceWhen to Consult
api-reference.mdFull type definitions, method signatures
embedding-providers.mdConfiguring OpenAI, Google, Cohere, Voyage, Ollama, etc.
store-adapters.mdDrizzle, Prisma, Raw SQL setup and schema
extractors.mdPDF, image, audio, video, file extractors
connectors.mdNotion, Google Drive, OneDrive, Dropbox
batteries.mdReranker, Eval harness, Debug panel
cli-commands.mdinit, add, upgrade, doctor, debug
patterns.mdSearch endpoints, multi-tenant, chat integration
troubleshooting.mdCommon issues, debugging, performance

Version Information

  • Skill Version: 1.0.0
  • Unrag CLI Version: 0.3.2
  • Config Version: 2

Key Source Files

When you need to look at source code:

FilePurpose
packages/unrag/registry/core/types.tsAll TypeScript types
packages/unrag/registry/core/context-engine.tsContextEngine class
packages/unrag/registry/manifest.jsonExtractors, connectors, batteries metadata
packages/unrag/cli/commands/*.tsCLI command implementations
apps/web/content/docs/**/*.mdxDocumentation pages

スコア

総合スコア

70/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です