Introduction
GraphRAG.js is a pure TypeScript library that enhances vector search with graph structures. It provides a unified API for building and querying knowledge graphs using multiple state-of-the-art graph RAG algorithms.
What is Graph RAG?
RAG (Retrieval-Augmented Generation) traditionally uses vector similarity search to find relevant chunks of text, then feeds those chunks to an LLM for generating answers.
Graph RAG goes beyond simple vector search by building and leveraging graph structures to:
- Include connected information, not just similar text
- Understand how entities and concepts relate
- Access community-level summaries and patterns
- Follow relationship chains to find indirect connections
Why GraphRAG.js?
One API, Multiple Algorithms
GraphRAG.js provides a single, consistent API that works with five different graph RAG algorithms. Change one line of code to switch between strategies:
import { createGraph } from "@graphrag-js/core";
import { lightrag, microsoftGraph, fastGraph, awsGraph, similarityGraph } from "@graphrag-js/core";
// Same API, different algorithm
const graph = createGraph({
model,
embedding,
provider: lightrag(), // swap this line to change everything
});Type-Safe and Modern
- Built with TypeScript for full type inference and IntelliSense
- Integrates seamlessly with Vercel AI SDK
- Works with any LLM provider (OpenAI, Anthropic, Google, etc.)
- Zero configuration for common use cases
Modular and Pluggable
- Algorithm packages: Install only the algorithms you need
- Storage adapters: Choose from in-memory, Neo4j, Qdrant, PostgreSQL, FalkorDB, or Redis
- Extensible: Create custom providers by implementing the
GraphProviderinterface
How It Works
All GraphRAG algorithms follow a two-step process:
1. Insert: Build the Graph
When you insert documents, the library:
- Chunks your text into manageable pieces
- Extracts entities, relationships, or other structures (algorithm-dependent)
- Builds a graph representation
- Creates vector embeddings for fast retrieval
await graph.insert("Your documents...");2. Query: Retrieve Enhanced Context
When you query, the library:
- Starts with vector similarity search to find relevant chunks
- Uses graph structures to expand and enrich the context
- Generates an answer using the LLM with graph-enhanced context
const { text } = await graph.query("Your question?");Algorithm Strategies
Each algorithm uses a different approach to build and traverse graphs:
| Algorithm | Strategy | Best For |
|---|---|---|
| Similarity | BFS expansion from similar chunks | Quick prototyping, simple use cases |
| LightRAG | Dual-level entity + relation vectors | General purpose, balanced cost |
| Microsoft | Community detection + reports | Deep thematic analysis |
| Fast | PageRank from seed entities | Fast, cheap, incremental updates |
| AWS | Fact-centric beam search | Multi-hop reasoning, cross-document connections |
Learn more about each algorithm in the Algorithms section.
What's Next?
- Installation - Install and set up GraphRAG.js
- Quick Start - Build your first graph in 5 minutes
- Core Concepts - Understand the key concepts
- Algorithms - Deep dive into each algorithm