1.0.0 โ€ข Published 4 months ago

@edgemaker/core v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Edgemaker

A TypeScript knowledge graph library inspired by Graphiti, designed for building temporally-aware AI memory systems.

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • Supabase project with pgvector enabled
  • OpenAI API key

Installation

npm install

Environment Setup

Create a .env.development file with your credentials:

SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
OPENAI_API_KEY=sk-your-openai-key
NODE_ENV=development

Database Setup

The database schema migration is located at:

supabase/migrations/20250101000001_edgemaker_initial_schema.sql

To apply the schema to your Supabase project, run this SQL in the Supabase Dashboard SQL Editor.

Basic Usage

import { Edgemaker, createEdgemakerConfig } from '@edgemaker/core';

// Create configuration
const config = createEdgemakerConfig({
  supabase: {
    url: process.env.SUPABASE_URL!,
    serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY!,
    anonKey: process.env.SUPABASE_ANON_KEY!,
  },
  llm: {
    openai: {
      apiKey: process.env.OPENAI_API_KEY!,
    },
  },
});

// Initialize Edgemaker
const edgemaker = new Edgemaker(config);

// Add an episode
const result = await edgemaker.addEpisode({
  content: "John bought coffee at Starbucks this morning",
  group_id: "project-1",
});

// Search the knowledge graph with different strategies
const searchResults = await edgemaker.search("coffee shops", {
  groupIds: ["project-1"],
  searchType: "story", // 'quick', 'story', 'character', 'factual', 'exploratory'
  limit: 10
});

// Advanced search with custom configuration
const advancedResults = await edgemaker.advancedSearch("character relationships", {
  searchConfig: {
    node_config: { method: 'cosine_similarity', limit: 15 },
    edge_config: { method: 'bm25', limit: 10 },
    reranking_strategy: 'node_distance'
  },
  filters: { groupIds: ["project-1"] }
});

๐Ÿงช Testing

# Run all tests
npm test

# Run only unit tests (fast, no external APIs)
npm run test:unit

# Run only integration tests (requires API keys)
npm run test:integration


# Run tests in watch mode
npm run test:watch
npm run test:watch:unit
npm run test:watch:integration

# Quick test (unit tests only)
npm run test:quick

# Build the project
npm run build

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ core/                 # Core Edgemaker class
โ”œโ”€โ”€ infrastructure/       # External integrations
โ”‚   โ”œโ”€โ”€ supabase/        # Database client
โ”‚   โ””โ”€โ”€ llm/             # LLM clients
โ”œโ”€โ”€ processors/          # Episode processing pipeline
โ”œโ”€โ”€ search/              # Search and retrieval
โ”œโ”€โ”€ prompts/             # LLM prompt templates
โ”œโ”€โ”€ types/               # TypeScript definitions
โ””โ”€โ”€ utils/               # Utility functions

supabase/
โ”œโ”€โ”€ migrations/          # Database schema
โ””โ”€โ”€ functions/           # Edge functions (optional)

๐Ÿ—ƒ๏ธ Database Schema

The system uses PostgreSQL with pgvector for:

  • Episodes: Raw input episodes
  • Entities: Extracted entities with embeddings
  • Entity Edges: Relationships between entities
  • Communities: Clustered entity groups

Key features:

  • Temporal relationship tracking
  • Vector similarity search
  • Current/historical edge management
  • Row-level security for multi-tenancy

๐Ÿง  Core Concepts

Episodes

Raw input data that gets processed into the knowledge graph.

Entities

Extracted people, places, objects, and concepts with:

  • Name embeddings for semantic search
  • Summaries and attributes
  • Temporal context

Edges

Relationships between entities with:

  • Fact embeddings
  • Temporal validity periods
  • Episode provenance

Search

Hybrid retrieval combining:

  • Vector similarity (embeddings)
  • Full-text search (PostgreSQL)
  • Graph traversal

๐Ÿšง Current Status

Implemented:

  • โœ… Project structure and TypeScript setup
  • โœ… Database schema with pgvector support
  • โœ… Supabase client configuration
  • โœ… OpenAI LLM client integration
  • โœ… Entity and edge extraction using LLM prompts
  • โœ… Deduplication and conflict resolution
  • โœ… Hybrid search implementation (vector + full-text + reranking)
  • โœ… Core Edgemaker class with full pipeline
  • โœ… Comprehensive test suite (unit + integration)
  • โœ… Health checks and monitoring

TODO:

  • Graph traversal search (BFS)
  • Community detection algorithms
  • Advanced documentation and examples
  • Performance optimization

๐Ÿ“š Documentation

See the docs/ directory for detailed architecture and implementation guides:

๐Ÿค Contributing

This is a work-in-progress project. Feel free to contribute by:

  1. Implementing missing features
  2. Adding tests
  3. Improving documentation
  4. Optimizing performance

๐Ÿ“„ License

MIT