rag_knowledge

command
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 12 Imported by: 0

README

RAG / Knowledge

Retrieval-Augmented Generation with knowledge.VectorKnowledge.

This example is fully offline by default. It ships:

  • store.go — a self-contained in-memory storage.VectorStore (cosine similarity).
  • embedder.go — a deterministic, hashing model.EmbeddingsProvider (no API key, no network).

main.go ingests four short documents, embeds and indexes them, runs a similarity search, and prints the top-k retrieved passages. If an LLM provider is configured in the environment it also feeds the retrieved passages to the model to produce a grounded answer.

Run

# Retrieval only — offline, no keys
go run ./examples/rag_knowledge/

# Also generate a grounded answer with a real LLM
OPENAI_API_KEY=sk-... go run ./examples/rag_knowledge/

Going to production

Swap the two stubs for real implementations:

  • storage.VectorStore → storage/adapters/qdrant
  • model.EmbeddingsProvider → a real embeddings provider

The knowledge.VectorKnowledge code stays identical.

Test

go test ./examples/rag_knowledge/   # asserts the most relevant doc ranks first

Documentation

Overview

Example: rag_knowledge — Retrieval-Augmented Generation with the Knowledge API.

What you'll learn:

  • How to build a RAG pipeline with knowledge.VectorKnowledge
  • How the Knowledge / VectorStore / EmbeddingsProvider interfaces fit together
  • How to ingest documents, embed them, and run a similarity search
  • How retrieved passages ground an LLM answer (optional, needs a provider)

This example is fully OFFLINE by default. It ships a self-contained in-memory VectorStore (cosine similarity) and a deterministic, hashing EmbeddingsProvider, so retrieval runs with NO API key and NO network. If an LLM provider is configured in the environment (OPENAI_API_KEY, etc.) the example additionally feeds the retrieved passages to that model to produce a grounded answer.

Prerequisites:

  • Go 1.22+
  • (optional) an LLM API key for the grounded-answer step

Run:

go run ./examples/rag_knowledge/          # retrieval only, offline
OPENAI_API_KEY=sk-... go run ./examples/rag_knowledge/   # + grounded answer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL