TypeScript RAG library with knowledge graph support.
- Why FlowRAG?
- Installation
- Quick Start
- Features
- Architecture
- Packages
- Use Cases
- Development
- Comparison
- License
FlowRAG solves common problems with existing RAG solutions:
π Python Complexity: No Python environments, virtual envs, or dependency conflicts. Pure TypeScript.
π₯οΈ Always-On Servers: Works as a library, not a service. Import, use, done.
βοΈ Serverless Unfriendly: Optimized for Lambda with fast cold starts and stateless queries.
π Storage Lock-in: File-based storage that's Git-friendly. Commit your knowledge base.
π Missing Knowledge Graphs: Combines vector search with entity relationships for richer context.
π§ Complex Setup: npm install and 10 lines of code to get started.
npm install @flowrag/core @flowrag/pipeline @flowrag/storage-json @flowrag/storage-sqlite @flowrag/storage-lancedb
npm install @flowrag/provider-local @flowrag/provider-geminiOr for a complete local setup:
npm install @flowrag/pipeline @flowrag/presetsFor AWS cloud deployment:
npm install @flowrag/provider-bedrock @flowrag/storage-s3 @flowrag/storage-opensearchimport { defineSchema } from '@flowrag/core';
import { createFlowRAG } from '@flowrag/pipeline';
import { createLocalStorage } from '@flowrag/presets';
// Define your schema
const schema = defineSchema({
entityTypes: ['SERVICE', 'DATABASE', 'PROTOCOL'],
relationTypes: ['USES', 'PRODUCES', 'CONSUMES'],
});
// Create RAG instance
const rag = createFlowRAG({
schema,
...createLocalStorage('./data'),
});
// Index documents
await rag.index('./content');
// Search
const results = await rag.search('how does authentication work');Define your own entity and relation types with optional custom fields:
const schema = defineSchema({
entityTypes: ['SERVICE', 'PROTOCOL', 'TEAM'],
relationTypes: ['PRODUCES', 'CONSUMES', 'OWNS'],
// Optional custom fields for richer metadata
entityFields: {
status: { type: 'enum', values: ['active', 'deprecated'], default: 'active' },
owner: { type: 'string' },
},
relationFields: {
syncType: { type: 'enum', values: ['sync', 'async'] },
},
});
// schema.isValidEntityType('SERVICE') β true
// schema.normalizeEntityType('UNKNOWN') β 'Other'Trace data flows through your system:
// Where does this data come from?
const sources = await rag.traceDataFlow('dashboard-metric', 'upstream');
// Where does this data go?
const consumers = await rag.traceDataFlow('user-event', 'downstream');Combines vector search with graph traversal:
- Vector search: Find semantically similar chunks
- Graph expansion: Follow entity relationships
- Merge & dedupe: Combine results
Search entities semantically by description, not just exact name:
const results = await rag.searchEntities('the service that handles login');
// [{ entity: { name: 'Auth Service', type: 'SERVICE', ... }, score: 0.92 }]Improve result quality with a post-retrieval reranking step:
import { LocalReranker } from '@flowrag/provider-local';
const rag = createFlowRAG({
schema,
...createLocalStorage('./data'),
reranker: new LocalReranker(), // Cross-encoder ONNX, fully offline
});Three implementations available:
LocalRerankerβ cross-encoder via ONNX (Xenova/ms-marco-MiniLM-L-6-v2), no API neededGeminiRerankerβ LLM-based relevance scoringBedrockRerankerβ Amazon Rerank API (amazon.rerank-v1:0)
Only re-process changed documents. Content is hashed (SHA-256) and compared on re-index:
await rag.index('./content'); // Skips unchanged docs
await rag.index('./content', { force: true }); // Re-index everythingDelete a document and automatically clean up orphaned entities and relations:
await rag.deleteDocument('doc:readme');Pluggable file parsing for non-text documents (PDF, DOCX, images, etc.):
const rag = createFlowRAG({
schema,
...createLocalStorage('./data'),
parsers: [new PDFParser(), new DocxParser()],
});Search results include source references for traceability:
const results = await rag.search('how does auth work');
// Each result includes: sources: [{ documentId, filePath, chunkIndex }]
// Plus document metadata fields in result.metadata (e.g., author, domain, version)Merge duplicate entities extracted by the LLM:
await rag.mergeEntities({
sources: ['Auth Service', 'AuthService', 'auth-service'],
target: 'Auth Service',
});Extension points for tracing, monitoring, and token tracking:
const rag = createFlowRAG({
// ...
observability: {
onLLMCall: ({ model, duration, usage }) => console.log(model, usage),
onEmbedding: ({ model, textsCount, duration }) => console.log(model, textsCount),
onSearch: ({ query, mode, resultsCount, duration }) => console.log(query, duration),
},
});Export the knowledge graph in multiple formats:
await rag.export('json'); // Entities + relations as JSON
await rag.export('csv'); // Relation table
await rag.export('dot'); // Graphviz digraphMulti-pass entity extraction for higher accuracy:
const rag = createFlowRAG({
// ...
options: { indexing: { extractionGleanings: 2 } },
});Pluggable RAG quality evaluation:
const rag = createFlowRAG({
// ...
evaluator: myEvaluator, // implements Evaluator interface
});
const result = await rag.evaluate('query', { reference: 'expected answer' });
// result.scores: { precision: 0.85, recall: 0.72, faithfulness: 0.91 }Full-featured command-line interface for local usage:
# Initialize data directory
flowrag init
# Index documents (with optional interactive entity review)
flowrag index ./content
flowrag index ./content --force # Re-index all documents
flowrag index ./content --interactive # Review extracted entities
# Search
flowrag search "how does OCPP work"
flowrag search "OCPP" --type entities # Search entities
flowrag search "ServiceA" --type relations # Show entity relations
flowrag search "query" --mode local --limit 20
# Knowledge graph
flowrag graph stats # Entity/relation breakdown
flowrag graph export # Export as DOT format
# Statistics
flowrag statsInteractive entity review during indexing with --interactive:
π Chunk chunk:abc123 β doc:readme
? Entities β select to keep:
β [SERVICE] becky-ocpp16 β "Backend OCPP 1.6..."
β [PROTOCOL] OCPP 1.6 β "Open Charge Point Protocol..."
β― [OTHER] WebSocket β "Communication protocol..."
? What next?
β Continue to relations
βοΈ Edit an entity
β Add new entity
π Show chunk content
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FlowRAG β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Schema Definition β Pipeline β Graph Traversal β
βββββββββββββββββββββββ΄βββββββββββββ΄βββββββββββββββββββββββββββ€
β STORAGE LAYER β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β KV β β Vector β β Graph β β
β β JSON/S3 β βSQLite/ β βSQLite/OS β β
β β Redis β βLance/OS β β β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β PROVIDERS β
β Embedder: Local ONNX β Gemini β Bedrock β
β Extractor: Gemini β Bedrock β
β Reranker: Local ONNX β Gemini β Bedrock β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Package | Version | Description | Status |
|---|---|---|---|
@flowrag/core |
Interfaces, schema, types | β Complete | |
@flowrag/pipeline |
Indexing & querying pipelines | β Complete | |
@flowrag/storage-json |
JSON file KV storage | β Complete | |
@flowrag/storage-sqlite |
SQLite graph & vector storage | β Complete | |
@flowrag/storage-lancedb |
LanceDB vector storage | β Complete | |
@flowrag/storage-s3 |
S3 KV storage | β Complete | |
@flowrag/storage-opensearch |
OpenSearch vector & graph storage | β Complete | |
@flowrag/provider-local |
Local AI provider (ONNX embeddings) | β Complete | |
@flowrag/provider-gemini |
Gemini AI provider (embeddings + extraction) | β Complete | |
@flowrag/provider-bedrock |
AWS Bedrock provider (embeddings + extraction) | β Complete | |
@flowrag/provider-openai |
OpenAI provider (embeddings + extraction) | β Complete | |
@flowrag/provider-anthropic |
Anthropic provider (extraction only) | β Complete | |
@flowrag/storage-redis |
Redis KV + vector storage | β Complete | |
@flowrag/presets |
Opinionated presets | β Complete | |
@flowrag/cli |
Command-line interface | β Complete | |
@flowrag/mcp |
MCP server for AI assistants | β Complete |
- β Complete: Fully implemented with 100% test coverage
- π§ In Progress: Currently being developed
- π Planned: Scheduled for future development
flowrag index ./content # Index your docs
flowrag search "query" # Search locally
# DB files committed to Git βimport { defineSchema } from '@flowrag/core';
import { createFlowRAG } from '@flowrag/pipeline';
import { BedrockEmbedder, BedrockExtractor } from '@flowrag/provider-bedrock';
import { S3KVStorage } from '@flowrag/storage-s3';
import { OpenSearchVectorStorage, OpenSearchGraphStorage } from '@flowrag/storage-opensearch';
export const handler = async (event: { query: string }) => {
const rag = createFlowRAG({
schema,
storage: {
kv: new S3KVStorage({ client: s3Client, bucket: 'my-rag-bucket', prefix: 'kv/' }),
vector: new OpenSearchVectorStorage({ client: osClient, dimensions: 1024 }),
graph: new OpenSearchGraphStorage({ client: osClient }),
},
embedder: new BedrockEmbedder(),
extractor: new BedrockExtractor(),
});
return await rag.search(event.query);
};| Purpose | Tool |
|---|---|
| Runtime | Node.js >=20 |
| Language | TypeScript (strict, isolatedDeclarations) |
| Build | tsdown (Rolldown-based) |
| Test | Vitest |
| Lint/Format | Biome |
| Schema | Zod |
npm install # Install dependencies
npm run build # Build all packages
npm test # Run all tests
npm run test:e2e # Run end-to-end tests
npm run lint # Lint code
npm run typecheck # Type checkThe docs site is built with VitePress and includes guides, API reference, provider docs, deployment patterns, and blog posts:
npm run docs:dev # Local dev server
npm run docs:build # Build for productionAI-friendly llms.txt and llms-full.txt are auto-generated and served from the docs site.
Releases are managed by bonvoy with independent versioning per package. CI runs on every push to main: tests (Node 20/22/24), e2e, lint, then auto-release and docs deploy.
| Aspect | LightRAG | FlowRAG |
|---|---|---|
| Language | Python | TypeScript |
| Model | Server (always running) | Library (import and use) |
| Indexing | Continuous, real-time | Batch, scheduled |
| Deploy | Container/server | Lambda-friendly |
| Storage | External DBs (Neo4j, Postgres) | File-based (Git-friendly) |
| Complexity | Feature-rich, many deps | Minimal, focused |
MIT
Inspired by LightRAG, built for TypeScript developers.