Skip to content

FalkorDB Graph Storage

The @graphrag-js/falkordb package provides lightweight graph storage using FalkorDB, a Redis-based graph database with Cypher query support.

Installation

bash
pnpm add @graphrag-js/falkordb

Features

  • Redis-Based - Built on Redis for reliability
  • Cypher Queries - Familiar query language
  • Low Latency - In-memory graph operations
  • Horizontal Scaling - Redis cluster support
  • Simple Deployment - Single Docker container
  • Cost-Effective - Lightweight alternative to Neo4j

Prerequisites

FalkorDB Instance

Option 1: Docker (Recommended)

bash
docker run -d \
  --name falkordb \
  -p 6379:6379 \
  -v falkordb-data:/data \
  falkordb/falkordb:latest

Option 2: Docker Compose

yaml
version: '3.8'
services:
  falkordb:
    image: falkordb/falkordb:latest
    ports:
      - "6379:6379"
    volumes:
      - falkordb-data:/data
    restart: unless-stopped

volumes:
  falkordb-data:

Verify Installation

bash
redis-cli ping
# PONG

redis-cli GRAPH.QUERY test "CREATE (n:Node {id: 'test'})"

Quick Start

typescript
import { createGraph } from '@graphrag-js/core';
import { fastGraph } from '@graphrag-js/fast';
import { falkorGraph } from '@graphrag-js/falkordb';
import { openai } from '@ai-sdk/openai';

const graph = createGraph({
  model: openai('gpt-4o-mini'),
  embedding: openai.embedding('text-embedding-3-small'),
  provider: fastGraph(), // FalkorDB works well with Fast GraphRAG
  storage: {
    graph: falkorGraph({
      host: 'localhost',
      port: 6379,
      password: undefined, // Optional
    }),
  }
});

await graph.insert('Your documents...');
const result = await graph.query('Your question?');

Configuration

falkorGraph(config)

typescript
interface FalkorGraphConfig {
  host?: string;       // Redis host (default: 'localhost')
  port?: number;       // Redis port (default: 6379)
  password?: string;   // Redis password (optional)
  workingDir?: string; // Namespace prefix (default: 'default')
}

Connection Examples

typescript
// Local instance
falkorGraph({
  host: 'localhost',
  port: 6379,
})

// Password-protected
falkorGraph({
  host: 'localhost',
  port: 6379,
  password: 'your-password',
})

// Remote instance
falkorGraph({
  host: 'falkordb.example.com',
  port: 6379,
  password: 'secure-password',
})

Usage Examples

Basic Graph Operations

typescript
import { falkorGraph } from '@graphrag-js/falkordb';

const graphStore = falkorGraph({
  host: 'localhost',
  port: 6379,
})('my-namespace');

// Add nodes
await graphStore.upsertNode('entity-1', {
  entity_type: 'person',
  description: 'Alice, data scientist',
  source_id: 'doc-1',
});

// Add edges
await graphStore.upsertEdge('entity-1', 'entity-2', {
  relationship: 'works_with',
  weight: 0.9,
  description: 'Collaborates on ML projects',
});

// Get node
const node = await graphStore.getNode('entity-1');

// Traverse graph
const edges = await graphStore.getNodeEdges('entity-1');

With Fast GraphRAG

FalkorDB is ideal for Fast GraphRAG's PageRank-based retrieval:

typescript
import { fastGraph } from '@graphrag-js/fast';
import { falkorGraph } from '@graphrag-js/falkordb';

const graph = createGraph({
  model: openai('gpt-4o-mini'),
  embedding: openai.embedding('text-embedding-3-small'),
  provider: fastGraph({
    entityTypes: ['PERSON', 'ORGANIZATION', 'CONCEPT'],
    pagerank: {
      damping: 0.85,
      maxIterations: 100,
    },
  }),
  storage: {
    graph: falkorGraph({
      host: 'localhost',
      port: 6379,
    }),
  }
});

Knowledge Graph Extraction

typescript
const kg = await graphStore.getKnowledgeGraph(
  'person',      // Node label
  2,             // Max depth
  1,             // Min degree
  true           // Inclusive
);

// Returns nodes and edges
console.log(kg.nodes.length);
console.log(kg.edges.length);

Direct Cypher Queries

For advanced use cases, use the FalkorDB SDK directly:

typescript
import FalkorDB from 'falkordb';

const client = FalkorDB.connect({
  host: 'localhost',
  port: 6379,
});

const graph = client.selectGraph('my-graph');

// Execute Cypher
const result = await graph.query(`
  MATCH (n:person)-[r:works_with]->(m:person)
  WHERE n.id = $nodeId
  RETURN m.id AS colleague, r.weight AS strength
`, { nodeId: 'entity-1' });

console.log(result.data);

Performance Characteristics

Benchmarks

On 100K nodes (M1 Mac):

OperationLatency
Node insert2-5ms
Edge insert2-5ms
Node lookup1-3ms
Graph traversal (depth=2)5-15ms
Cypher query (simple)5-10ms

Memory Usage

FalkorDB stores graphs in Redis memory:

  • Node: ~500 bytes per node
  • Edge: ~300 bytes per edge

Example: 100K nodes + 200K edges:

  • Nodes: 100K × 500 bytes = 50MB
  • Edges: 200K × 300 bytes = 60MB
  • Total: ~110MB

Limitations

Community Detection

FalkorDB does not currently support advanced graph algorithms like Leiden clustering. Use Neo4j if you need:

  • Community detection
  • Advanced centrality algorithms
  • Graph data science workflows

When to Use FalkorDB

Good for:

  • Fast GraphRAG and lightweight providers
  • Simple graph traversal
  • Cost-effective graph storage
  • Redis-familiar teams
  • Moderate-scale graphs (< 1M nodes)

Not recommended for:

  • Microsoft GraphRAG (needs Leiden clustering)
  • Complex graph analytics
  • Very large graphs (> 1M nodes)
  • Advanced graph algorithms

Production Deployment

Redis Persistence

Enable RDB and AOF for durability:

bash
docker run -d \
  --name falkordb \
  -p 6379:6379 \
  -v falkordb-data:/data \
  falkordb/falkordb:latest \
  --appendonly yes \
  --save 900 1 \
  --save 300 10

Redis Cluster

For high availability:

yaml
version: '3.8'
services:
  falkordb-1:
    image: falkordb/falkordb:latest
    ports:
      - "6379:6379"
    volumes:
      - falkordb-1-data:/data

  falkordb-2:
    image: falkordb/falkordb:latest
    ports:
      - "6380:6379"
    volumes:
      - falkordb-2-data:/data

  falkordb-3:
    image: falkordb/falkordb:latest
    ports:
      - "6381:6379"
    volumes:
      - falkordb-3-data:/data

volumes:
  falkordb-1-data:
  falkordb-2-data:
  falkordb-3-data:

Monitoring

bash
# Monitor memory usage
redis-cli info memory

# Monitor graph operations
redis-cli monitor

# Check graph stats
redis-cli GRAPH.QUERY my-graph "MATCH (n) RETURN count(n)"

Backup Strategy

bash
# Manual backup (RDB)
redis-cli SAVE
cp /data/dump.rdb /backups/dump-$(date +%Y%m%d).rdb

# Restore
cp /backups/dump-20240101.rdb /data/dump.rdb
docker restart falkordb

Troubleshooting

Connection Refused

Error: Error: connect ECONNREFUSED

Solution:

  1. Verify FalkorDB is running: docker ps | grep falkordb
  2. Check port: 6379
  3. Test: redis-cli ping

Out of Memory

Error: OOM command not allowed when used memory > 'maxmemory'

Solution:

bash
# Increase memory limit
docker run -d \
  --name falkordb \
  -p 6379:6379 \
  falkordb/falkordb:latest \
  --maxmemory 4gb \
  --maxmemory-policy allkeys-lru

Graph Not Found

Error: Graph 'xxx' not found

Solution:

  • Graphs are created automatically on first write
  • Check namespace configuration
  • Verify graph name matches

Cost Considerations

DeploymentCostBest For
Self-hostedFree + hostingAny scale, full control
Redis Cloud$5+/monthManaged hosting
Redis EnterpriseCustomEnterprise features

FalkorDB is significantly cheaper than Neo4j for simple graph workloads.

Comparison with Neo4j

FeatureFalkorDBNeo4j
Query LanguageCypherCypher
Performance (small graphs)FasterSlower
Performance (large graphs)SlowerFaster
Community Detection✅ (GDS)
Advanced Algorithms✅ (GDS)
Memory UsageLowerHigher
Setup ComplexityLowerHigher
CostLowerHigher

Recommendation: Use FalkorDB for Fast GraphRAG, LightRAG, or AWS GraphRAG. Use Neo4j for Microsoft GraphRAG.

Next Steps

Released under the Elastic License 2.0.