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

@badriana/rag-core

v0.1.0

Published

Lightweight, production-ready RAG Ingestion Engine for document parsing, text normalization, chunking, and vector embedding pipelines

Readme

@badriana/rag-core

npm version license bundle size typescript

Universal Multimodal RAG Ingestion Engine untuk Node.js & TypeScript.
Solusi tanpa lock-in untuk mengekstrak Teks, Gambar, Tabel, dan Rumus menjadi Unit Pengetahuan (Knowledge Chunks) bervektor.

@badriana/rag-core memperlakukan Teks, Gambar, Tabel, dan Rumus sebagai Unit Pengetahuan (Knowledge Chunks). Library ini mengelola seluruh pipeline ingesti dokumen: parsing dokumen, ekstraksi gambar, pemrosesan Vision AI, chunking hierarkis, pembuat vektor embedding, indikator progress real-time, dan statistik performa ingesti.


📦 Instalasi

npm install @badriana/rag-core

🚀 Quick Start (30 Detik)

Langsung coba ingesti dokumen PDF/TXT menjadi Knowledge Chunks bervektor lengkap dengan progress bar dan statistik:

import { createDocument } from '@badriana/rag-core';


const result = await createDocument({
  source: fileBuffer,
  filename: 'buku-fisika.pdf',
  // 1. Integrasikan Embedding API favorit Anda
  embedder: async (texts) => openRouterEmbedder(texts),
  // 2. Opsional: AI Vision untuk mengubah gambar PDF menjadi Embedded Knowledge Chunk
  imageProcessor: async (image) => geminiVisionProcessor(image),
  // 3. Opsional: Progress bar real-time untuk UI
  onProgress: (progress) => {
    console.log(`[${progress.stage}] ${progress.percentage}% - ${progress.message}`);
  },
});

console.log(result.chunks); // Array Knowledge Chunks (Text, Image, Table, Equation)
console.log(result.stats);  // Metrik waktu & statistik konten dokumen

📊 Diagram Alur Pipeline Ingesti Dokumen

   Dokumen Input (PDF / TXT / DOCX / Base64)
                       │
                       ▼
              1. parse()               [Parsing 10% -> 25%]  (Ekstraksi Teks & Gambar)
                       │
                       ▼
       2. imageProcessor() [Optional]  [Processing Images 40% -> 60%] (Vision AI / OCR)
                       │
                       ▼
              3. chunk()               [Chunking 65%] (Generasi Text, Image, Table & Equation Chunks)
                       │
                       ▼
             4. embedChunks()          [Embedding 75% -> 95%] (Generasi Vektor Embedding)
                       │
                       ▼
  [ Hasil: Document + Knowledge Chunks + Stats + Progress Completed 100% ]

⏳ Indikator Progress Real-Time (onProgress)

Sangat cocok untuk menampilkan Progress Bar (0% ➔ 100%) pada aplikasi Web/Frontend:

await createDocument({
  source: pdfBuffer,
  embedder: openRouterEmbedder,
  onProgress: (progress) => {
    console.log(`Tahap: ${progress.stage}`);       // 'parsing' | 'processing_images' | 'chunking' | 'embedding' | 'completed'
    console.log(`Persentase: ${progress.percentage}%`); // 0 sampai 100
    console.log(`Pesan: ${progress.message}`);       // "Processing image 2 of 5..."
  },
});

📊 Statistik Performa & Metrik Konten (result.stats)

Dapatkan analisis waktu eksekusi milidetik dan metrik konten dokumen secara otomatis:

console.log(result.stats);
// {
//   characters: 52821,      // Total jumlah karakter
//   words: 9312,            // Total jumlah kata
//   images: 18,             // Total gambar yang diekstrak
//   chunks: 57,             // Total knowledge chunks yang dihasilkan
//   pages: 24,              // Total halaman PDF
//   parseTimeMs: 210,       // Waktu parsing (ms)
//   chunkTimeMs: 15,        // Waktu chunking (ms)
//   embeddingTimeMs: 532,   // Waktu API Embedding (ms)
//   totalTimeMs: 757        // Total waktu ingesti (ms)
// }

📖 Struktur Hasil Objek (result)

{
  "document": {
    "id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
    "content": "Isi dokumen murni yang sudah dibersihkan...",
    "chunks": [ /* Koleksi gabungan Knowledge Chunks */ ],
    "metadata": { "title": "buku-fisika.pdf", "mimeType": "application/pdf" }
  },
  "chunks": [
    {
      "id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
      "type": "text",
      "index": 0,
      "startOffset": 0,
      "endOffset": 350,
      "source": { "filename": "buku-fisika.pdf" },
      "content": "Paragraf persamaan percepatan gravitasi...",
      "embedding": [0.012, -0.045, 0.891]
    },
    {
      "id": "e89ac10b-12aa-4372-a567-9e02b2c3d999",
      "type": "image",
      "kind": "diagram",
      "index": 1,
      "startOffset": 0,
      "endOffset": 0,
      "source": { "filename": "buku-fisika.pdf", "page": 12 },
      "content": "Diagram memperlihatkan kurva gaya gravitasi terhadap jarak r...",
      "image": {
        "dataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
        "mimeType": "image/png",
        "page": 12
      },
      "metadata": {
        "title": "Diagram Gravitasi",
        "caption": "Grafik hubungan gaya gravitasi dengan massa dua benda",
        "page": 12
      },
      "embedding": [0.034, -0.112, 0.745]
    }
  ],
  "images": [
    {
      "dataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
      "mimeType": "image/png",
      "page": 12
    }
  ],
  "stats": {
    "characters": 52821,
    "words": 9312,
    "images": 1,
    "chunks": 2,
    "pages": 12,
    "parseTimeMs": 210,
    "chunkTimeMs": 15,
    "embeddingTimeMs": 532,
    "totalTimeMs": 757
  }
}

💡 Alur Upload Gambar Cloud Storage (Pola Imutabel)

Bebas menentukan Cloud Storage pilihan Anda (AWS S3, Supabase, Cloudinary) dengan pola imutabel:

// 1. Ingesti dokumen
const { chunks, stats } = await createDocument({
  source,
  filename,
  embedder,
  imageProcessor,
  onProgress: (p) => updateProgressBar(p.percentage),
});

// 2. Transposisi imutabel & upload ImageChunks ke Cloud Storage
const updatedChunks = await Promise.all(
  chunks.map(async (chunk) => {
    if (chunk.type !== 'image') return chunk;

    const publicUrl = await uploadToSupabaseStorage(chunk.image.dataUrl);
    return {
      ...chunk,
      image: {
        ...chunk.image,
        url: publicUrl,
      },
    };
  })
);

// 3. Simpan seluruh chunks (Teks & Gambar) ke Vector DB dalam 1 query!
await prisma.knowledgeChunk.createMany({
  data: updatedChunks,
});

📄 Lisensi

MIT © badrian