Skip to content

TypeScript API

Jean-Baptiste THERY edited this page Jul 14, 2026 · 14 revisions

TypeScript API

Ragmir publishes three ESM packages for Node.js 20 or later:

Package Use it for
@jcode.labs/ragmir Index and retrieve cited project evidence
@jcode.labs/ragmir-chat Generate a cited answer from supplied passages with a local GGUF model
@jcode.labs/ragmir-tts Render reviewed text as local WAV or explicit online MP3 audio

Use the CLI or MCP server when an agent only needs evidence. Use these APIs when a Node.js process owns the workflow. All project paths resolve from cwd or the current working directory.

Core retrieval

import { ingest, search, type SearchOptions } from "@jcode.labs/ragmir"

const cwd = process.cwd()
await ingest({ cwd })

const options: SearchOptions = { cwd, topK: 5, explain: true }
const results = await search("Which decision changed the rollout?", options)

Results include relativePath, citation, chunkIndex, exact text, line ranges, page ranges when available, structural context, and optional score explanations.

Main Core operations

Area Exports
Project and sources initProject, setupProject, loadConfig, knowledgeBaseIdentity, discoverKnowledgeBases, getKnowledgeBaseContext, getKnowledgeBaseSourceCatalog, listSourceEntries, addSourceEntries
Index and retrieve ingest, audit, previewChunks, search, ask, research, expandCitation, compactSearchResults, compactResearchReport, evaluateGoldenQueries
Operations doctor, securityAudit, ingestionLimits, accessLogUsageReport, destroyIndex, redactText, routePrompt
Optional local capabilities enableSemanticEmbeddings, pullEmbeddingModel, clearTransformersCache, inspectPdfOcr, configurePdfOcr, extractPdfPage
Integrations serveMcp, installAgentSkills, installSkill, inspectAgentIntegration, parseAgentTargets, rgrCommand

Core exports named option and result types for every public signature, including IngestOptions, SearchOptions, EnableSemanticEmbeddingsResult, PullEmbeddingModelResult, and RedactionCount.

Local Chat

import { generateChatAnswer, type ChatSource } from "@jcode.labs/ragmir-chat"

const sources: ChatSource[] = [
  {
    relativePath: "docs/rollout.md",
    chunkIndex: 0,
    text: "The rollout moved from Friday to Monday after the review.",
  },
]

const result = await generateChatAnswer({
  question: "What changed?",
  profile: "lite",
  sources,
})

Use setupChatModel once, then generateChatAnswer for normal generation. doctor and modelCacheExists verify local readiness. Advanced exports cover custom runtimes, the line-delimited JSON server, model verification, prompt construction, and citation validation. Normal generation never enables remote model resolution.

TTS

import { renderSpeech } from "@jcode.labs/ragmir-tts"

const result = await renderSpeech({
  textFile: ".ragmir/reports/release-brief.md",
  outputPath: ".ragmir/audio/release-brief.wav",
  engine: "transformers",
  language: "en",
  allowRemoteModels: false,
})

renderSpeech renders caller-supplied text. It does not retrieve evidence or create a summary. doctor, isTtsLanguage, mmsModelForLanguage, edgeVoiceForLanguage, and modelCacheExists support runtime inspection and custom integrations.

The complete list of runtime exports, constants, option types, and result types is versioned in the canonical API reference.

Clone this wiki locally