/railtracks:rag [describe the data source and what you want to retrieve]from Railtracks
Builds a RAG pipeline using the railtracks framework: ingest documents into a vector store and retrieve relevant passages to answer questions.
Ships in Railtracks. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The user wants to build a retrieval-augmented generation (RAG) pipeline using the railtracks framework: $ARGUMENTS
The pipeline has two paths:
Write path (ingestion): Loader → Chunker → Embedder → VectorStore
Read path (retrieval): query → Embedder → VectorStore.search → RetrievalResult
RetrievalRuntime orchestrates both paths. It takes a chunker, embedder, and store at construction time, then exposes ingest_all() / ingest() for writes and retrieve() for reads.
| Stage | Input | Output |
|---|---|---|
| Loader | source (file, URL, dataset) | Document |
| Chunker | Document | Chunk |
| Embedder | Chunk.content | EmbeddedChunk |
| Store | EmbeddedChunk | stored StoreEntry |
| Retrieve | query string | RetrievalResult (ranked RetrievedChunk list) |
from railtracks.retrieval.loaders import (
TextLoader, # .txt / .md files
CSVLoader, # rows → documents; content_columns, id_column, ignore_columns
JSONLoader, # .json / .jsonl files
PyPDFLoader, # PDF file or folder; breakdown_strategy="page" (default), "paragraph", or "document"
HuggingFaceDatasetLoader, # HF Hub datasets; pass dataset_name, split, content_columns
LangChainLoaderAdapter, # wrap any LangChain document loader
)
from railtracks.retrieval.chunking import (
RecursiveCharacterChunker, # general text; chunk_size (chars), overlap
MarkdownHeaderChunker, # heading-aware splits for .md content
SentenceChunker, # sentence windows; chunk_size (# sentences), overlap
SemanticChunker, # embedding-driven breakpoints; variable chunk size
FixedTokenChunker, # hard token budget; chunk_size (tokens), overlap
)
from railtracks.retrieval.embedding import (
OpenAIEmbedding, # default model: "text-embedding-3-small"
AzureEmbedding, # Azure OpenAI routing
OllamaEmbedding, # local dev; model, api_base
LiteLLMEmbedding, # any LiteLLM-supported provider
)
from railtracks.retrieval.stores import (
VectorStore, # store implementation; wraps a backend
InMemoryVectorBackend, # tests and small corpora; no persistence by default
ChromaBackend, # local / persistent / HTTP modes
ChromaCloudBackend, # managed Chroma Cloud
PgvectorBackend, # Postgres + pgvector; production
)
pip install "railtracks[retrieval-core]" # minimum (no connectors)
pip install "railtracks[retrieval]" # all connectors
pip install "railtracks[chroma]" # Chroma only
pip install "railtracks[huggingface]" # HuggingFace datasets
pip install "railtracks[ocr]" # PyPDF + OCR (requires Tesseract)
$ARGUMENTS.RecursiveCharacterChunker for plain text, MarkdownHeaderChunker for structured docs, SentenceChunker for narrative text. Use SemanticChunker only when chunk boundaries matter semantically.EmbeddingModelMismatchError). Otherwise match the provider the project already uses, or one whose API key is configured (embedders and their settings: https://docs.railtracks.org/retrieval/components/embeddings/methods/); otherwise ask the user. Use OllamaEmbedding for local/offline dev.InMemoryVectorBackend for demos/tests, ChromaBackend for local persistence, PgvectorBackend for production.RetrievalRuntime — pass chunker, embedder, store. Initialize async backends with await backend.initialize() or the ChromaBackend.create() factory.runtime.ingest_all(loader=...). Print stats. Handle documents_failed gracefully.runtime.retrieve(query, top_k=...). Return or format result.chunks.retrieve as a @rt.function_node tool, or call it in a pre-invoke hook.if __name__ == "__main__": block — include both an ingest path and a query example so the user can run it immediately.import asyncio
from railtracks.retrieval import RetrievalRuntime
from railtracks.retrieval.loaders import TextLoader
from railtracks.retrieval.chunking import RecursiveCharacterChunker
from railtracks.retrieval.embedding import OpenAIEmbedding
from railtracks.retrieval.stores import VectorStore, InMemoryVectorBackend
async def main():
runtime = RetrievalRuntime(
chunker=RecursiveCharacterChunker(chunk_size=1000, overlap=200),
embedder=OpenAIEmbedding(),
store=VectorStore(InMemoryVectorBackend()),
batch_size=100,
)
stats = await runtime.ingest_all(loader=TextLoader("data/my_file.txt"))
print(f"chunks embedded: {stats.chunks_embedded}")
result = await runtime.retrieve("your question here", top_k=5)
for rc in result.chunks:
print(f"[rank={rc.rank} score={rc.score:.3f}] {rc.chunk.content[:200]}")
if __name__ == "__main__":
asyncio.run(main())
import asyncio
from railtracks.retrieval import RetrievalRuntime
from railtracks.retrieval.loaders import TextLoader
from railtracks.retrieval.chunking import RecursiveCharacterChunker
from railtracks.retrieval.embedding import OpenAIEmbedding
from railtracks.retrieval.stores import VectorStore, ChromaBackend
async def create_runtime() -> RetrievalRuntime:
backend = await ChromaBackend.create(
collection_name="my-collection",
path="./my_db",
)
return RetrievalRuntime(
chunker=RecursiveCharacterChunker(chunk_size=1000, overlap=200),
embedder=OpenAIEmbedding(model="text-embedding-3-small"),
store=VectorStore(backend),
batch_size=100,
)
async def main():
runtime = await create_runtime()
stats = await runtime.ingest_all(loader=TextLoader("data/my_file.txt"))
print(
f"loaded={stats.documents_loaded} chunks={stats.chunks_embedded} skipped={stats.documents_skipped}"
)
result = await runtime.retrieve("your question here", top_k=5)
for rc in result.chunks:
print(f"[rank={rc.rank} score={rc.score:.3f}]\n{rc.chunk.content}\n")
if __name__ == "__main__":
asyncio.run(main())
from railtracks.retrieval import RetrievalRuntime
from railtracks.retrieval.runtime import BatchIngested, DocumentFailed, DocumentSkipped
async def ingest_with_progress(runtime: RetrievalRuntime, loader) -> None:
async for event in runtime.ingest(loader=loader):
if isinstance(event, BatchIngested):
print(f"batch {event.batch_index}: {len(event.embedded_chunks)} chunks written")
elif isinstance(event, DocumentFailed):
# stage is "load", "chunk", "embed", or "store"; document_id is None for "load"
print(f"FAILED at {event.stage}: {event.source} — {event.errors!r}")
elif isinstance(event, DocumentSkipped):
print(f"skipped (unchanged): {event.document_id}")
from railtracks.retrieval.loaders import PyPDFLoader
from railtracks.retrieval.chunking import RecursiveCharacterChunker
# breakdown_strategy="page" (default): one Document per page
# breakdown_strategy="paragraph": one Document per non-empty paragraph on each page
# breakdown_strategy="document": one Document for the whole PDF
# Pass a folder instead of a file to load every .pdf in it, recursively
loader = PyPDFLoader("data/report.pdf", breakdown_strategy="page")
chunker = RecursiveCharacterChunker(chunk_size=800, overlap=100)
from railtracks.retrieval.loaders import CSVLoader
# content_columns: the columns whose text gets embedded (joined in order)
# id_column: a column that uniquely identifies each row, for stable upserts
# every other column is stored as metadata, unless listed in ignore_columns
loader = CSVLoader(
file_path="data/products.csv",
content_columns=["description"],
id_column="product_id",
)
from railtracks.retrieval.loaders import HuggingFaceDatasetLoader
loader = HuggingFaceDatasetLoader(
dataset_name="squad",
split="train",
content_columns=["context"],
)
from railtracks.retrieval.stores import StoreScope
user_scope = StoreScope(labels={"user_id": "u123", "org_id": "acme"})
# Write: ingest only into this scope
stats = await runtime.ingest_all(loader=loader, scope=user_scope)
# Read: retrieve only from this scope (no scope = unscoped entries only)
result = await runtime.retrieve("question", top_k=5, scope=user_scope)
# Admin search across every tenant must be explicit
from railtracks.retrieval import ALL_SCOPES
everything = await runtime.retrieve("question", top_k=5, scope=ALL_SCOPES)
# Delete all documents for exactly this scope (labels must match exactly:
# clearing {"org_id": "acme"} does not touch {"user_id": "u123", "org_id": "acme"})
await runtime.store.clear(user_scope)
import railtracks as rt
from railtracks.retrieval import RetrievalRuntime
runtime: RetrievalRuntime = ... # constructed at startup
@rt.function_node
async def search_knowledge_base(query: str) -> str:
"""Search the knowledge base for relevant context.
Args:
query: The natural language question to look up.
Returns:
Relevant excerpts from the knowledge base, ranked by similarity.
"""
result = await runtime.retrieve(query, top_k=5)
if not result.chunks:
return "No relevant documents found."
return "\n\n---\n\n".join(
f"[score={rc.score:.3f}]\n{rc.chunk.content}" for rc in result.chunks
)
RagAgent = rt.agent_node(
"RAG Agent",
tool_nodes=[search_knowledge_base],
llm=rt.llm.AnthropicLLM("claude-sonnet-5-5"),
system_message="You are a helpful assistant. Always search the knowledge base before answering.",
)
flow = rt.Flow(name="RAG Flow", entry_point=RagAgent)
from railtracks.retrieval.chunking import SentenceChunker
# chunk_size: number of sentences per chunk
# overlap: number of sentences shared between consecutive chunks
chunker = SentenceChunker(chunk_size=6, overlap=1)
from railtracks.retrieval.embedding import OllamaEmbedding
embedder = OllamaEmbedding(model="nomic-embed-text", api_base="http://localhost:11434")
# Re-ingest will upsert (content-hash skips unchanged docs)
# To explicitly remove (document_id is the Document.id UUID):
from uuid import UUID
await runtime.delete_document(document_id=UUID("1f0c9b6e-0000-4000-8000-000000000000"))
# Pass the scope it was ingested with to delete only that tenant's copy
await runtime.delete_document(document_id=UUID("1f0c9b6e-0000-4000-8000-000000000000"), scope=user_scope)
await ChromaBackend.create(...), which handles initialization.EmbeddingModelMismatchError on a mismatch.ingest_all() and a loader that streams (astream()), so documents are processed as they load.documents_failed in the ingestion stats and surface any failures to the user. One unreadable file or failing document is reported as a DocumentFailed (see its stage and source) and the rest still ingest; pass on_error="raise" to RetrievalRuntime only when a single bad document should stop the run.ChromaBackend with a path, or in PgvectorBackend; InMemoryVectorBackend keeps them only until the process restarts.RetrievalRuntime once at startup and reuse it across requests.retrieve() the user's natural-language question as the query.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Python, OpenAI, Ollama, PostgreSQL, pgvector, Langchain, Hugging Face
npx claudepluginhub railtownai/railtracks --plugin railtracks3 skills in this plugin
/agent-builderBuild an agent using the railtracks Python framework. Use when the user wants to create an AI agent, tool-calling workflow, or multi-agent system with railtracks./middlewareAdd middleware to a railtracks agent or node (retries, logging, timing, guardrails, context injection). Use when the user wants to wrap, retry, guard, or observe node or LLM calls.Other plugins' skills for the same job