Nous.KnowledgeBase (nous v0.16.2)

View Source

LLM-compiled personal knowledge base system.

Inspired by Karpathy's vision: raw documents get ingested, an LLM compiles them into a markdown wiki with summaries, backlinks, and cross-references. You can Q&A over it, generate outputs, and run health checks.

Quick Start — Plugin Mode

Add the KB plugin to any agent for interactive use:

agent = Nous.Agent.new("openai:gpt-4",
  plugins: [Nous.Plugins.KnowledgeBase],
  deps: %{
    kb_config: %{
      store: Nous.KnowledgeBase.Store.ETS,
      kb_id: "my_kb"
    }
  }
)

{:ok, result} = Nous.Agent.run(agent, "Ingest this article: ...")
{:ok, result} = Nous.Agent.run(agent, "What do we know about GenServers?")

Quick Start — Workflow Mode

For batch operations, use the workflow API:

# Batch ingest
{:ok, state} = Nous.KnowledgeBase.ingest(
  [%{title: "Article 1", content: "..."}],
  kb_config: config
)

# Health check
{:ok, state} = Nous.KnowledgeBase.health_check(kb_config: config)

Quick Start — Agent Behaviour Mode

For a KB-specialized agent:

agent = Nous.Agent.new("openai:gpt-4",
  behaviour_module: Nous.Agents.KnowledgeBaseAgent,
  plugins: [Nous.Plugins.KnowledgeBase],
  deps: %{kb_config: %{store: Nous.KnowledgeBase.Store.ETS, kb_id: "my_kb"}}
)

Architecture

The KB system has four composable layers:

  1. Data model & storeDocument, Entry, Link, HealthReport structs with a pluggable Store behaviour (ETS, SQLite, etc.)
  2. Plugin & toolsNous.Plugins.KnowledgeBase integrates with any agent, providing 9 tools (search, read, ingest, add_entry, link, backlinks, list, health_check, generate)
  3. Workflows — Pre-built DAG pipelines for ingest, incremental update, health check, and output generation
  4. Agent behaviourNous.Agents.KnowledgeBaseAgent for specialized KB curation and reasoning

Summary

Functions

Get backlinks for an entry.

Generate structured output from the knowledge base.

Get a specific entry by slug or ID.

Run a health check audit on the knowledge base.

Incrementally update the knowledge base with new or changed documents.

Ingest documents through the full compilation pipeline.

List all documents, optionally filtered.

List all entries, optionally filtered.

Get related entries (connected by any link direction).

Search knowledge base entries directly.

Functions

backlinks(store_mod, store_state, entry_id)

Get backlinks for an entry.

generate(output_type, opts)

Generate structured output from the knowledge base.

Parameters

  • output_type - :report, :summary, or :slides
  • opts - Must include :kb_config and :topic

get_entry(store_mod, store_state, slug_or_id)

Get a specific entry by slug or ID.

health_check(opts)

Run a health check audit on the knowledge base.

incremental_update(documents, opts)

Incrementally update the knowledge base with new or changed documents.

ingest(documents, opts)

Ingest documents through the full compilation pipeline.

Options

  • :kb_config - Required. Knowledge base configuration map.
  • :compiler_model - Model for compilation (default: "openai:gpt-4o-mini")
  • :embedding - Embedding provider module
  • :embedding_opts - Embedding options

list_documents(store_mod, store_state, opts \\ [])

List all documents, optionally filtered.

list_entries(store_mod, store_state, opts \\ [])

List all entries, optionally filtered.

search(store_mod, store_state, query, opts \\ [])

Search knowledge base entries directly.