rag
Skill6 starsChanged 23 days agoApache-2.0View on GitHub
Build multi-modal RAG pipelines with graph-enhanced retrieval in Go using saige/rag. Covers chunking, multi-retriever fusion, reranking, HyDE, evaluation metrics, and PostgreSQL + pgvector storage.
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 113
Search options: types.WithCandidatePool(k) sets how many fused candidates reach the reranker, and types.WithMinScore(s) is a threshold in …
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
rag
A Go library for multi-modal Retrieval-Augmented Generation with graph-enhanced retrieval, part of the saige SDK.
What it does
saige/rag models documents as hierarchical structures (Document -> Section -> ContentVariant) where each section can have multiple modality representations (text, image, table, audio). It provides a pluggable pipeline for ingesting documents, generating embeddings, performing hybrid search (vector + BM25 + graph), reranking, and assembling context with citations.
When to use
- Ingesting documents (PDF, text, images) into a searchable vector store
- Building RAG pipelines with multi-modal content support
- Combining vector search with knowledge graph traversal
- Evaluating retrieval and generation quality
- Deduplicating documents by content fingerprint
Usage
Install
go get github.com/urmzd/saigeCreate a pipeline
import (
"github.com/urmzd/saige/rag"
"github.com/urmzd/saige/rag/pgstore"
"github.com/urmzd/saige/rag/types"
"github.com/urmzd/saige/postgres"
)
// Connect to PostgreSQL 18 (requires the pgvector and pg_search extensions).
pool, _ := postgres.NewPool(ctx, postgres.Config{URL: "postgres://localhost:5432/mydb"})
postgres.RunMigrations(ctx, pool, postgres.MigrationOptions{})
store, _ := pgstore.New(pgstore.Config{Pool: pool})
pipe, err := rag.New(rag.Config{Store: store},
rag.WithContentExtractor(myExtractor),
rag.WithEmbedders(myEmbedderRegistry),
rag.WithRecursiveChunker(512, 50),
rag.WithBM25(nil),
rag.WithMMR(0.7),
)Ingest a document
result, err := pipe.Ingest(ctx, &types.RawDocument{
SourceURI: "https://example.com/paper.pdf",
MIMEType: "application/pdf",
Data: pdfBytes,
})Search
results, err := pipe.Search(ctx, "attention mechanism", types.WithLimit(5), types.WithContextAssembly(4096))
fmt.Println(results.Context.Prompt) // context with citationsWith knowledge graph integration
pipe, err := rag.New(rag.Config{Store: store},
rag.WithContentExtractor(extractor),
rag.WithGraph(kgGraph), // enables entity extraction + graph retrieval
)Key interfaces
| Interface | Purpose |
Pipeline | Orchestrate ingest, search, update, delete, reconstruct |
Store | Document CRUD + vector search |
ContentExtractor | Raw bytes -> structured Document |
Chunker | Split long sections |
EmbedderRegistry | Dispatch embedding by ContentType |
Configuration options
| Option | Purpose |
WithStore(s) | Set the document store, or set rag.Config.Store (required) |
WithContentExtractor(ext) | Set the content extractor (required) |
WithRecursiveChunker(max, overlap) | Recursive text chunking |
WithSemanticChunker(thresh, min, max) | Semantic similarity chunking |
WithEmbedders(reg) | Set the embedder registry (optional, needed for search) |
WithGraph(g) | Enable knowledge graph entity extraction (optional) |
WithBM25(cfg) | Enable BM25 lexical retrieval. Over pgstore it searches the store's pg_search index; over a store without keyword search the index is in memory, so call rag.RebuildIndex(ctx, pipe) once after rag.New when the store already holds documents |
WithParentContext() | Expand hits to parent section context |
WithMMR(lambda) | MMR diversity reranking |
WithCrossEncoder(scorer) | Cross-encoder reranking |
WithHyDE(llm, n) | HyDE query expansion |
WithCompression(llm) | LLM-based context compression |
WithDedupBehavior(b) | Set dedup behavior: DedupSkip (default) or DedupReplace |
WithStoreOriginals(true) | Persist raw document bytes |
Search options: types.WithCandidatePool(k) sets how many fused candidates reach the reranker, and types.WithMinScore(s) is a threshold in [0, 1] on the normalized fused score (1.0 keeps only hits ranked first by every retriever), applied before reranking.
Evaluation
import "github.com/urmzd/saige/rag/eval"
// Retrieval metrics (pure functions).
precision := eval.ContextPrecision(hits, relevantUUIDs)
recall := eval.ContextRecall(hits, relevantUUIDs)
ndcg := eval.NDCG(hits, relevantUUIDs, 10)
mrr := eval.MRR(hits, relevantUUIDs)
// Generation metrics (require LLM).
faith, _, _ := eval.Faithfulness(ctx, response, contextText, llm)
correctness, _ := eval.AnswerCorrectness(ctx, response, groundTruth, llm)Agent tool bindings
import "github.com/urmzd/saige/rag/tool"
tools := tool.NewTools(pipeline)
// rag_search, rag_lookup, rag_update, rag_delete, rag_reconstructCLI
saige knowledge ingest --db "$SAIGE_RAG_DB" --file paper.pdf --mime application/pdf
saige knowledge sync --db "$SAIGE_RAG_DB" --dir docs --include '**/*.md' --exclude 'drafts/**' --prune
saige knowledge search --db "$SAIGE_RAG_DB" --query "attention mechanism"
saige knowledge show --db "$SAIGE_RAG_DB" --uuid <variant-uuid>
saige knowledge delete --db "$SAIGE_RAG_DB" --uuid <doc-uuid>Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- BULDEE/ai-craftsman-superpowers★ 35same name
- nimadorostkar/Claude-Skills-collection★ 33same name
- belos-street/skill-kit★ 8same name
- hajekim/agentic-design-patterns-skills★ 4same name
- phucbm/skills★ 2same name
- hajekim/agentic-design-patterns-extension★ 1same name
- Shugar86/my-agent★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- llms.txtllms.txt
- agentSkill
- knowledge-graphSkill
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
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.

