Skip to content

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:

typescript
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 GraphProvider interface

How It Works

All GraphRAG algorithms follow a two-step process:

1. Insert: Build the Graph

When you insert documents, the library:

  1. Chunks your text into manageable pieces
  2. Extracts entities, relationships, or other structures (algorithm-dependent)
  3. Builds a graph representation
  4. Creates vector embeddings for fast retrieval
typescript
await graph.insert("Your documents...");

2. Query: Retrieve Enhanced Context

When you query, the library:

  1. Starts with vector similarity search to find relevant chunks
  2. Uses graph structures to expand and enrich the context
  3. Generates an answer using the LLM with graph-enhanced context
typescript
const { text } = await graph.query("Your question?");

Algorithm Strategies

Each algorithm uses a different approach to build and traverse graphs:

AlgorithmStrategyBest For
SimilarityBFS expansion from similar chunksQuick prototyping, simple use cases
LightRAGDual-level entity + relation vectorsGeneral purpose, balanced cost
MicrosoftCommunity detection + reportsDeep thematic analysis
FastPageRank from seed entitiesFast, cheap, incremental updates
AWSFact-centric beam searchMulti-hop reasoning, cross-document connections

Learn more about each algorithm in the Algorithms section.

What's Next?

Released under the Elastic License 2.0.