Skip to main content

Structured knowledge extraction from meeting transcripts โ†’ PostgreSQL ontology graph

Project description

๐Ÿง  Ontology Engine

Transform unstructured text into structured knowledge graphs โ€” powered by LLMs, stored in PostgreSQL.

PyPI Python Tests License


An open-source, schema-driven framework that extracts entities, relationships, decisions, and action items from meeting transcripts (or any text) into a PostgreSQL-backed knowledge graph. Designed for multi-agent AI systems that need shared organizational memory.

Architecture

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚              Ontology Engine                  โ”‚
                    โ”‚                                              โ”‚
  Text Input โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
  (meetings,       โ”‚  โ”‚  BRONZE  โ”‚  โ”‚  SILVER  โ”‚  โ”‚   GOLD   โ”‚   โ”‚
   documents,      โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚   โ”‚
   reports)        โ”‚  โ”‚ Raw doc  โ”œโ”€โ”€โ–บ Schema-  โ”œโ”€โ”€โ–บ Entity   โ”‚   โ”‚
                    โ”‚  โ”‚ storage  โ”‚  โ”‚ driven   โ”‚  โ”‚ resoln + โ”‚   โ”‚
                    โ”‚  โ”‚ (append  โ”‚  โ”‚ extract  โ”‚  โ”‚ merge +  โ”‚   โ”‚
                    โ”‚  โ”‚  only)   โ”‚  โ”‚ + valid  โ”‚  โ”‚ embeds   โ”‚   โ”‚
                    โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
                    โ”‚                                    โ”‚         โ”‚
                    โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
                    โ”‚  โ”‚  Agent   โ”‚  โ”‚                             โ”‚
                    โ”‚  โ”‚   SDK    โ—„โ”€โ”€โ”˜  PostgreSQL + pgvector      โ”‚
                    โ”‚  โ”‚ + REST   โ”‚     (JSONB knowledge graph)    โ”‚
                    โ”‚  โ”‚   API    โ”‚                                โ”‚
                    โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜                                โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   AI Agents   โ”‚
                    โ”‚  query, write โ”‚
                    โ”‚  subscribe    โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Bronze Layer โ€” Immutable, append-only raw document store with deduplication (SHA-256).

Silver Layer โ€” Schema-driven LLM extraction pipeline: preprocessing โ†’ 4-pass extraction (entities, relations, decisions, actions) โ†’ 3-layer auto-correction.

Gold Layer โ€” Entity resolution (Jaro-Winkler + alias matching + embeddings), deduplication, and computed aggregation. The canonical knowledge graph.

Agent SDK โ€” Python async client + FastAPI REST API for AI agents to query, write, and subscribe to the knowledge graph.

Quick Start

Install

pip install ontology-engine[all]

Extract knowledge from text (3 lines)

import asyncio
from ontology_engine.pipeline.engine import PipelineEngine
from ontology_engine.core.config import OntologyConfig

async def main():
    engine = await PipelineEngine.create(OntologyConfig())
    result = await engine.ingest("meeting_notes.md")
    print(f"Found {len(result.extraction.entities)} entities, "
          f"{len(result.extraction.decisions)} decisions")

asyncio.run(main())

Or use the CLI

# Set your LLM API key
export GEMINI_API_KEY="your-key"

# Process a single file
ontology-engine ingest meeting.md -o result.json

# Process a directory
ontology-engine ingest-dir ./meetings/ --pattern "*.md"

# Use a domain schema
ontology-engine ingest meeting.md --schema edtech

Features

๐ŸŸค Bronze Layer โ€” Raw Document Storage

  • Append-only, immutable document store
  • SHA-256 content deduplication
  • Source tracking (type, URI, format, language)
  • CLI: ontology-engine bronze list, ontology-engine bronze show <id>

โšช Silver Layer โ€” Schema-Driven Extraction

  • Preprocessing: text cleaning, topic segmentation, coreference resolution
  • 4-Pass extraction: Entities โ†’ Relations โ†’ Decisions โ†’ Action Items
  • 3-Layer validation: factual correction, semantic checks, consistency enforcement
  • 6 built-in entity types: Person, Decision, ActionItem, Project, Risk, Deadline
  • 13 link types: participates_in, makes, assigned_to, relates_to, generates, supersedes, depends_on, mitigates, blocks, reports_to, collaborates_with, owns, deadline_for
  • Provenance tracking: every fact traced to source text + extraction pass

๐ŸŸก Gold Layer โ€” Entity Resolution & Embeddings

  • Entity resolution: exact match, alias matching, Jaro-Winkler fuzzy matching
  • Configurable thresholds: auto-merge (>0.95), review (0.80โ€“0.95), distinct (<0.80)
  • Embedding generation: OpenAI text-embedding-3-small for semantic search
  • Incremental builds: only process new Silver entities
  • Full rebuild: clear and recompute from Silver at any time

๐Ÿค– Agent SDK & REST API

  • Python async client (OntologyClient): query, search, assert entities/links, subscribe to events
  • Agent registry: agents register what they produce/consume
  • FastAPI REST API: 12 endpoints for HTTP integration
  • Event system: PostgreSQL LISTEN/NOTIFY for real-time change notifications

๐Ÿ“‹ Domain Schemas (YAML)

  • Define custom entity types, link types, and properties per domain
  • Built-in schemas: default, edtech, finance
  • Extraction hints for LLM guidance
  • Validation rules per schema

Domain Schemas

Define domain-specific ontologies in YAML:

domain: edtech
version: "1.0.0"
description: "Education technology domain"

entity_types:
  - name: Student
    description: "A student or learner"
    properties:
      - { name: student_id, type: string, required: true }
      - { name: grade_level, type: string }
      - { name: enrollment_status, type: enum, enum_values: ["active","graduated","withdrawn"] }
    extraction_hint: "ๅญฆ็”Ÿใ€ๅญฆๅ‘˜ใ€ๅŒๅญฆ็ญ‰"

  - name: Course
    description: "A course or class"
    properties:
      - { name: course_code, type: string, required: true }
      - { name: credits, type: integer }

link_types:
  - { name: enrolled_in, source_types: [Student], target_types: [Course] }
  - { name: teaches, source_types: [Tutor], target_types: [Course] }

extraction:
  system_prompt: |
    You are an education-focused knowledge extraction system.
    Extract students, courses, knowledge units, and their relationships.

Use with CLI: ontology-engine ingest meeting.md --schema edtech

Manage schemas:

ontology-engine schema list          # List available schemas
ontology-engine schema show edtech   # Show schema details
ontology-engine schema validate my_schema.yaml

Agent SDK

Build AI agents that read and write to the shared knowledge graph:

from ontology_engine.sdk.client import OntologyClient

async with OntologyClient("postgresql://localhost/ontology") as client:
    # Register your agent
    await client.register_agent(
        id="meeting-bot",
        display_name="Meeting Bot",
        produces=["Decision", "ActionItem"],
        consumes=["Person", "Project"],
    )

    # Write: assert entities and links
    decision_id = await client.assert_entity(
        entity_type="Decision",
        name="Adopt microservices architecture",
        properties={"detail": "Migrate monolith to microservices by Q3", "rationale": "Scalability"},
        source="meeting:2024-01-15",
        confidence=0.95,
    )

    # Read: query and search
    decisions = await client.query("Decision", filters={"status": "active"})
    results = await client.search("microservices", limit=5)

    # Traverse the graph
    linked = await client.get_linked(decision_id, direction="outgoing", depth=2)

    # Schema introspection (for autonomous agents)
    schema = await client.describe("Decision")

    # Subscribe to changes (PostgreSQL LISTEN/NOTIFY)
    async def on_change(event):
        print(f"Entity changed: {event.entity_type} {event.entity_id}")

    await client.subscribe("Decision", on_change)

API Reference

Start the API server:

# Via module
python -m ontology_engine.api.server --db-url "postgresql://..." --port 8000

# Or with uvicorn
uvicorn ontology_engine.api.server:app --reload

Endpoints

Method Path Description
GET /api/v1/health Health check
GET /api/v1/query Query entities by type + filters
GET /api/v1/search?q=... Full-text search (trigram similarity)
GET /api/v1/entity/{id} Get entity by ID
GET /api/v1/linked/{id} Graph traversal from entity
POST /api/v1/ingest Ingest raw text (Bronze)
POST /api/v1/assert/entity Create/update entity
POST /api/v1/assert/link Create relationship
GET /api/v1/describe/{type} Schema introspection
GET /api/v1/agents List registered agents
POST /api/v1/agents/register Register an agent

Interactive docs at http://localhost:8000/docs (Swagger UI).

Configuration

Environment Variables

Variable Description Default
GEMINI_API_KEY Google Gemini API key โ€”
OPENAI_API_KEY OpenAI API key (for embeddings) โ€”
DATABASE_URL PostgreSQL connection URL โ€”

Config File

{
  "llm": {
    "provider": "gemini",
    "model": "gemini-2.5-flash",
    "api_key": "your-key",
    "temperature": 0.1
  },
  "database": {
    "url": "postgresql://localhost:5432/ontology",
    "db_schema": "ontology"
  },
  "pipeline": {
    "min_confidence": 0.6,
    "segment_topics": true,
    "resolve_coreferences": true
  },
  "known_entities": {
    "aliases": {
      "Yann": ["Yannๅ“ฅ", "้ƒญๅš", "้ชŒ"]
    }
  }
}

Use with: ontology-engine -c config.json ingest meeting.md

LLM Model Tiers

Tier Default Model Used For
Fast gemini-2.0-flash-lite Preprocessing, simple tasks
Default gemini-2.5-flash Extraction, validation
Strong gemini-2.5-pro Complex reasoning, conflict resolution

Supports pluggable LLM providers: Gemini (default), OpenAI.

Database Setup

# Initialize schema (creates tables, indexes, extensions)
ontology-engine init --db-url "postgresql://user:pass@localhost:5432/ontology"

Requires PostgreSQL 15+ with extensions:

  • pgvector โ€” vector similarity search
  • pg_trgm โ€” trigram text search

Or use Docker:

docker compose up -d

Testing

# Unit tests (no API key or DB required, fast)
pytest tests/ --ignore=tests/integration/ -v

# Integration tests (requires GEMINI_API_KEY + PostgreSQL)
pytest tests/integration/ -v -s

# All tests
pytest -v

# With coverage
pytest --cov=ontology_engine --cov-report=term-missing

Project Structure

ontology-engine/
โ”œโ”€โ”€ src/ontology_engine/
โ”‚   โ”œโ”€โ”€ core/              # Types, config, errors, schema format
โ”‚   โ”‚   โ”œโ”€โ”€ types.py           # 6 Entity + 13 Link type definitions
โ”‚   โ”‚   โ”œโ”€โ”€ config.py          # Pydantic configuration models
โ”‚   โ”‚   โ”œโ”€โ”€ schema_format.py   # Domain schema Pydantic models
โ”‚   โ”‚   โ”œโ”€โ”€ schema_registry.py # Schema loader + registry
โ”‚   โ”‚   โ””โ”€โ”€ errors.py          # Custom exception hierarchy
โ”‚   โ”œโ”€โ”€ pipeline/          # Bronzeโ†’Silver extraction pipeline
โ”‚   โ”‚   โ”œโ”€โ”€ preprocessor.py    # Text cleaning, segmentation
โ”‚   โ”‚   โ”œโ”€โ”€ extractor.py       # 4-Pass LLM extraction
โ”‚   โ”‚   โ”œโ”€โ”€ validator.py       # 3-Layer auto-correction
โ”‚   โ”‚   โ””โ”€โ”€ engine.py          # Pipeline orchestrator
โ”‚   โ”œโ”€โ”€ fusion/            # Silverโ†’Gold aggregation
โ”‚   โ”‚   โ”œโ”€โ”€ entity_resolver.py # Jaro-Winkler + alias entity resolution
โ”‚   โ”‚   โ”œโ”€โ”€ gold_builder.py    # Gold layer builder
โ”‚   โ”‚   โ””โ”€โ”€ embeddings.py      # OpenAI embedding generation
โ”‚   โ”œโ”€โ”€ storage/           # PostgreSQL persistence
โ”‚   โ”‚   โ”œโ”€โ”€ bronze.py          # Bronze document repository
โ”‚   โ”‚   โ”œโ”€โ”€ repository.py      # Silver entity/link CRUD
โ”‚   โ”‚   โ”œโ”€โ”€ gold_repository.py # Gold entity/link CRUD
โ”‚   โ”‚   โ””โ”€โ”€ schema.py          # DDL + migrations
โ”‚   โ”œโ”€โ”€ sdk/               # Agent SDK
โ”‚   โ”‚   โ”œโ”€โ”€ client.py          # OntologyClient (async)
โ”‚   โ”‚   โ””โ”€โ”€ registry.py        # Agent registration + discovery
โ”‚   โ”œโ”€โ”€ api/               # FastAPI REST API
โ”‚   โ”‚   โ”œโ”€โ”€ server.py          # App factory + lifespan
โ”‚   โ”‚   โ”œโ”€โ”€ routes.py          # 12 API endpoints
โ”‚   โ”‚   โ””โ”€โ”€ models.py          # Request/response schemas
โ”‚   โ”œโ”€โ”€ llm/               # LLM provider abstraction
โ”‚   โ”‚   โ”œโ”€โ”€ base.py            # Abstract interface
โ”‚   โ”‚   โ”œโ”€โ”€ gemini.py          # Google Gemini
โ”‚   โ”‚   โ””โ”€โ”€ openai.py          # OpenAI
โ”‚   โ”œโ”€โ”€ events/            # Event system
โ”‚   โ”‚   โ””โ”€โ”€ notifier.py        # PG LISTEN/NOTIFY pub/sub
โ”‚   โ””โ”€โ”€ cli.py             # CLI entry point (Click + Rich)
โ”œโ”€โ”€ domain_schemas/        # Built-in YAML domain schemas
โ”‚   โ”œโ”€โ”€ default.yaml
โ”‚   โ”œโ”€โ”€ edtech.yaml
โ”‚   โ””โ”€โ”€ finance.yaml
โ”œโ”€โ”€ tests/                 # 258 unit + 46 integration tests
โ”œโ”€โ”€ docs/                  # Documentation
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ docker-compose.yml
โ””โ”€โ”€ CHANGELOG.md

Contributing

We welcome contributions! Here's how to get started:

# Clone and install in development mode
git clone https://github.com/Yvnminc/ontology-engine.git
cd ontology-engine
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[all,dev]"

# Run linting
ruff check src/ tests/
ruff format src/ tests/

# Run type checking
mypy src/ontology_engine/

# Run tests
pytest -v

Please open an issue first to discuss significant changes.

Roadmap

โœ… Phase 1: Static Ontology (current โ€” v0.1.0)

  • Bronze โ†’ Silver โ†’ Gold full pipeline
  • Schema-driven extraction with YAML domain schemas
  • Entity resolution + embedding generation
  • Agent SDK + FastAPI REST API
  • PostgreSQL + pgvector storage
  • CLI tools

๐Ÿ”œ Phase 2: Kinetic Ontology

  • Real-time streaming ingestion
  • Incremental Gold updates on every ingest
  • Conflict detection and resolution
  • Temporal queries (point-in-time knowledge graph)
  • Webhook integrations

๐Ÿ”ฎ Phase 3: Dynamic Ontology

  • Schema evolution and migration
  • Cross-domain knowledge fusion
  • Autonomous agent orchestration
  • Graph neural network embeddings
  • Multi-tenant deployment

License

MIT ยฉ Yann Guo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ontology_engine-0.1.0.tar.gz (140.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ontology_engine-0.1.0-py3-none-any.whl (93.9 kB view details)

Uploaded Python 3

File details

Details for the file ontology_engine-0.1.0.tar.gz.

File metadata

  • Download URL: ontology_engine-0.1.0.tar.gz
  • Upload date:
  • Size: 140.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ontology_engine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb01e268015d6888ad88cd5c8609561b4b836710583e221c33d762a5d1d8484a
MD5 bedb1c3f1c65dd2ad9dc0563a53176d4
BLAKE2b-256 eb92dcffc684e7a18cbeb12ff18ec7038a1adf3f2741478161919f4935db943f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ontology_engine-0.1.0.tar.gz:

Publisher: publish.yml on Yvnminc/ontology-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ontology_engine-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ontology_engine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e50aef2035853eafd5db34acf188d63ba797ea9cfe374f251870e6f2709677ee
MD5 aa1491bbd808cdd2f7150b97b45767db
BLAKE2b-256 2b297f72266a929b1f1478d98672a760a5757863cf7caeb37d9fb1c0a124f11c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ontology_engine-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Yvnminc/ontology-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page