agentleFS
urmzdurmzd/saige/skills/knowledge-graph/SKILL.md

knowledge-graph

Skill6 starsChanged 23 days agoApache-2.0View on GitHub

Build and query knowledge graphs with PostgreSQL + pgvector. Ingest episodes, extract entities/relations via LLM, and search facts by semantic similarity or keyword. Use when working with knowledge graphs, entity extraction, or graph storage.

Files
SKILL.md

knowledge-graph

Build and query knowledge graphs using saige/knowledge.

Quick Start

import (
    "github.com/urmzd/saige/rag/knowledge"
    "github.com/urmzd/saige/postgres"
    "github.com/urmzd/saige/agent/provider/ollama"
)

// Connect to PostgreSQL (requires pgvector extension).
pool, _ := postgres.NewPool(ctx, postgres.Config{URL: "postgres://localhost:5432/mydb"})
postgres.RunMigrations(ctx, pool, postgres.MigrationOptions{})

client, _ := ollama.NewClient(ollama.Config{Host: "http://localhost:11434", Model: "qwen3.5:4b", EmbeddingModel: "nomic-embed-text"})
graph, _ := knowledge.New(knowledge.Config{},
    knowledge.WithPostgres(pool),
    knowledge.WithExtractor(knowledge.NewOllamaExtractor(client)),
    knowledge.WithEmbedder(knowledge.NewOllamaEmbedder(client)),
)
defer graph.Close(ctx)

// Ingest
graph.IngestEpisode(ctx, &knowledge.EpisodeInput{
    Name: "notes", Body: "Alice presented the roadmap.", Source: "meeting",
})

// Search
facts, _ := graph.SearchFacts(ctx, "roadmap")

Key Operations

MethodPurpose
IngestEpisodeExtract entities/relations from text and store them
SearchFactsFull-text search on relation facts
GetEntityRetrieve a single entity by ID
GetNodeGet a node with its neighborhood (depth N)
GetGraphFull graph snapshot for visualization
ApplyOntologyConstrain entity/relation types

Ontology

graph.ApplyOntology(ctx, &knowledge.Ontology{
    EntityTypes:   []knowledge.EntityTypeDef{{Name: "Person", Description: "A human"}},
    RelationTypes: []knowledge.RelationTypeDef{{Name: "works_on", SourceType: "Person", TargetType: "Project"}},
})

The ontology is passed to the extractor, which is asked to use its types. Extracted types that match an ontology type ignoring case and punctuation are rewritten to the ontology's spelling; other types are kept as extracted. Build the graph with knowledge.WithStrictOntology() to drop entities and relations whose type is not in the ontology.

Agent Tool Bindings

import "github.com/urmzd/saige/rag/knowledge/tool"

tools := tool.NewTools(graph, tool.WithGroupID(tenantID))
// kg_search, kg_ingest, both bound to one graph group the model cannot change

In a RAG pipeline, rag.WithGraphNamespace(tenantID) sets the group documents are ingested into and the graph retriever searches.

CLI

saige knowledge search --backend kg --db "$SAIGE_KG_DB" --query "Who presented?"
saige knowledge ingest --backend kg --db "$SAIGE_KG_DB" --name "meeting" --text "Alice presented the roadmap."
saige knowledge graph export  --db "$SAIGE_KG_DB"
saige knowledge graph neighbors   --db "$SAIGE_KG_DB" --id <entity-uuid> --depth 2

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.