agentleFS
lauren-frameworklauren-framework/lauren-ai/skills/rag-pipeline/SKILL.md

rag-pipeline

Skill0 starsChanged 6 months agoMITView on GitHub

Builds a full RAG (Retrieval-Augmented Generation) pipeline using KnowledgeBase, InMemoryVectorStore, TextLoader, and FixedSizeChunker. Use when grounding agent answers in document corpora, indexing company docs/FAQs for search, or attaching a search tool to an agent via kb.as_tool() or @use_knowledge_sources.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    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
  1. Very specific:

    Use InMemoryVectorStore directly in tests — no external dependencies needed.

    line 107

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Use codemap find "SymbolName" to locate any symbol before reading — it gives exact file + line range and is faster than grep across the whole repo.

RAG Pipeline (Document Chunking + Embedding + Retrieval)

Overview

Documents
    │
    ▼  TextLoader / MarkdownLoader
    │
    ▼  FixedSizeChunker / SentenceChunker
    │
    ▼  InMemoryVectorStore (TF-IDF by default)
    │
    ▼  KnowledgeBase.search(query)
    │
    ▼  Agent tool call → grounded answer

Quick start

from lauren_ai._knowledge import KnowledgeBase, TextLoader, FixedSizeChunker
from lauren_ai._memory._vector import InMemoryVectorStore

kb = KnowledgeBase(
    store=InMemoryVectorStore(),
    chunker=FixedSizeChunker(chunk_size=512, overlap=64),
)

# Index documents
await kb.load(TextLoader("docs/faq.txt"))
await kb.load(TextLoader("The quick brown fox jumps over the lazy dog.", is_file=False))

# Search
results = await kb.search("quick fox", top_k=3)
for r in results:
    print(f"{r.score:.3f} — {r.content}")

Attaching KB to an agent (as a tool)

from lauren_ai import agent, use_tools

@agent(model="claude-opus-4-6", system="Answer questions using the knowledge base.")
@use_tools(kb.as_tool(name="search_company_docs", top_k=5))
class RAGAgent: ...

The as_tool() method returns a @tool()-decorated async function whose schema the LLM can call. Results include content, score, and any metadata stored at index time.


Attaching KB via KnowledgeSource (module-level)

from lauren_ai import agent, use_knowledge_sources, AgentModule
from lauren_ai._knowledge import KnowledgeBase, KnowledgeSource, TextLoader
from lauren_ai._memory._vector import InMemoryVectorStore

kb = KnowledgeBase(store=InMemoryVectorStore())
ks = KnowledgeSource(
    kb=kb,
    tool_name="search_docs",
    top_k=5,
    loaders=[TextLoader("docs/faq.txt")],  # loaded at app startup
)

@agent(model="claude-opus-4-6")
@use_knowledge_sources("search_docs")
class SupportAgent: ...

AIModule = AgentModule.for_root(
    agents=[SupportAgent],
    knowledge=[ks],
    imports=[LLMModule.for_root(cfg)],
)

Chunkers

ChunkerDescription
FixedSizeChunker(chunk_size=512, overlap=64)Fixed character windows with optional overlap
SentenceChunker(max_chunk_size=512)Splits at sentence boundaries

Testing a RAG pipeline

Use InMemoryVectorStore directly in tests — no external dependencies needed. The TF-IDF implementation handles basic keyword matching out of the box.

kb = KnowledgeBase(store=InMemoryVectorStore())
await kb.load(TextLoader("Python is a programming language.", is_file=False))
results = await kb.search("programming language")
assert len(results) > 0
assert "Python" in results[0].content

For testing the full agent flow, queue a search tool call in MockTransport:

mock.queue_tool_use("search_company_docs", {"query": "refund policy"})
mock.queue_response(completion("Our refund policy allows 30-day returns."))

Reference

  • lauren_ai._knowledge: KnowledgeBase, KnowledgeSource, TextLoader, FixedSizeChunker, SentenceChunker
  • lauren_ai._memory._vector: InMemoryVectorStore
  • lauren_ai._memory: MemoryResult
  • Skills: managing-memory, vector-store-integration, embedding-model-ingestion

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.