Skip to content

Installation

GraphRAG SDK is designed as a collection of modular packages. Install only what you need.

Package Manager

We recommend using pnpm, but npm and yarn work too:

bash
# Using pnpm (recommended)
pnpm install

# Using npm
npm install

# Using yarn
yarn install

Core Package

The core package provides the main API and interfaces:

bash
pnpm add graphrag-sdk

TIP

The core package contains only interfaces, createGraph(), and query(). You'll need to install a provider package and storage separately.

Provider Packages

Choose a graph provider:

bash
# Lexical Graph — entity extraction, community detection, search strategies
pnpm add @graphrag-sdk/lexical

The lexical package includes composable processors and search strategies:

Processors (run during indexing):

  • chunkEntityGeneration() — extract entities and relationships from chunks
  • entityCommunityGeneration() — Leiden clustering + community reports
  • similarChunkConnection() — build similarity edges between chunks
  • hypotheticalQuestionGeneration() — generate question embeddings per chunk

Search strategies (run during queries):

  • naiveSearch() — pure vector search baseline
  • entityEnhancedSearch() — chunk search + entity graph traversal
  • localCommunitySearch() — entity neighborhood + community context
  • globalCommunitySearch() — community reports for thematic queries
  • similarChunkTraversalSearch() — BFS along SIMILAR_TO edges
  • hypotheticalQuestionSearch() — question-to-question matching

Presets (pre-configured pipelines):

  • microsoftGraphragPreset() — entities + communities (Microsoft GraphRAG)
  • lightragPreset() — entities only (LightRAG)
  • fastGraphragPreset() — entities + similarity edges
  • awsGraphragPreset() — entities + communities (AWS style)

Storage Packages

In-Memory Storage (Development)

For development and testing:

bash
pnpm add @graphrag-sdk/in-memory-storage

The memory package includes:

  • inMemoryGraph() — in-memory graph using Cytoscape
  • inMemoryVector() — in-memory vector store with cosine similarity
  • inMemoryKV() — in-memory key-value store
  • jsonKV() — file-based JSON key-value store
  • jsonGraph() — file-based JSON graph store

External Storage (Production)

For production deployments, install external storage adapters:

bash
# Neo4j graph database
pnpm add @graphrag-sdk/neo4j

# Qdrant vector database
pnpm add @graphrag-sdk/qdrant

# FalkorDB graph database
pnpm add @graphrag-sdk/falkordb

# PostgreSQL + pgvector
pnpm add @graphrag-sdk/pgvector

# Redis key-value store
pnpm add @graphrag-sdk/redis

AI SDK Provider

GraphRAG SDK uses the Vercel AI SDK for LLM and embedding models. Install your preferred provider:

bash
# OpenAI
pnpm add ai @ai-sdk/openai

# Anthropic
pnpm add ai @ai-sdk/anthropic

# Google (Gemini)
pnpm add ai @ai-sdk/google

Minimal Installation

bash
pnpm add graphrag-sdk @graphrag-sdk/lexical @graphrag-sdk/in-memory-storage ai @ai-sdk/openai

TypeScript Configuration

GraphRAG SDK requires TypeScript 5.0 or later. Add this to your tsconfig.json:

json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true
  }
}

Environment Variables

Set up your API keys for the LLM provider:

bash
# .env
OPENAI_API_KEY=your_openai_api_key

# Or for Anthropic
ANTHROPIC_API_KEY=your_anthropic_api_key

# Or for Google
GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key

Verification

Verify your installation:

typescript
import { createGraph, query } from "graphrag-sdk";
import { lexicalGraph, chunkEntityGeneration, naiveSearch } from "@graphrag-sdk/lexical";
import { inMemoryGraph, inMemoryVector, inMemoryKV } from "@graphrag-sdk/in-memory-storage";
import { openai } from "@ai-sdk/openai";

const graph = createGraph({
  graph: lexicalGraph({
    graphStoreFactory: inMemoryGraph,
    vectorStoreFactory: inMemoryVector,
    kvStoreFactory: inMemoryKV,
    pipeline: [chunkEntityGeneration()],
  }),
  model: openai("gpt-4o-mini"),
  embedding: openai.embedding("text-embedding-3-small"),
});

console.log("GraphRAG SDK installed successfully!");

Next Steps

Released under the Elastic License 2.0. Made with ❤️ by Narek.