new-rag

A command that creates a starter RAG pipeline. RAG, or retrieval-augmented generation, lets an AI answer using information retrieved from documents or websites.

In plain words
What is it for?
Starting RAG projects with in-memory storage, local FAISS or Chroma storage, PostgreSQL with pgvector, or the managed Pinecone service.
Why use it?
It provides a prepared starting file and asks which vector store should hold searchable document data, reducing the setup work for a new pipeline.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/codeblockz/langchain-community-plugin/new-rag
Clone the repo
git clone --depth 1 https://github.com/Codeblockz/langchain-community-plugin
Per session 21 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,455 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00021 $0.03455
Opus 5 $0.00010 $0.01728
Sonnet 5 $0.00004 $0.00691
Haiku 4.5 $0.00002 $0.00346

Measured yesterday against content hash 31e5ad9cc074, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

new-rag scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/new-rag.md · 602 lines

How it starts

The opening of the file, as written. The whole thing — 602 lines — stays where its author put it; the contents beside it link to each section on GitHub.

New RAG Pipeline Command

Create a new RAG pipeline file with best practices baked in.

Workflow

  1. Ask the user which vector store they want:

    • InMemory - Quick prototyping, no persistence
    • FAISS - Local, file-based persistence
    • Chroma - Local with server option
    • pgvector - PostgreSQL-based
    • Pinecone - Managed cloud service
  2. Get filename from argument or ask user (default: rag_pipeline.py)

  3. Generate the RAG file using the appropriate template below

  4. Inform user about next steps (install dependencies, configure embeddings)

Templates

InMemory Template

"""
RAG Pipeline using InMemoryVectorStore

Install: pip install langchain langchain-openai
"""
from langchain_community.document_loaders import WebBaseLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_core.vectorstores import InMemoryVectorStore
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import OpenAIEmbeddings, ChatOpenAI


# 1. Load documents
def load_documents(urls: list[str]):
    """Load documents from URLs."""
    docs = []
    for url in urls:
        loader = WebBaseLoader(url)
        docs.extend(loader.load())
    return docs


# 2. Split into chunks
def split_documents(docs, chunk_size=1000, chunk_overlap=200):
    """Split documents into chunks for embedding."""
    splitter = RecursiveCharacterTextSplitter(
        chunk_size=chunk_size,
        chunk_overlap=chunk_overlap,
        add_start_index=True,
    )
    return splitter.split_documents(docs)


# 3. Create vector store
def create_vectorstore(chunks):
    """Create vector store from document chunks."""
    embeddings = OpenAIEmbeddings()
    vectorstore = InMemoryVectorStore.from_documents(chunks, embeddings)
    return vectorstore


# 4. Build RAG chain
def build_rag_chain(vectorstore):
    """Build the RAG chain."""
    retriever = vectorstore.as_retriever(search_kwargs={"k": 4})

    prompt = ChatPromptTemplate.from_template("""
Answer the question based only on the following context.
If you cannot answer based on the context, say "I don't know."

Context:
{context}

Question: {question}

Answer:
""")

    llm = ChatOpenAI(model="gpt-4o", temperature=0)

    def format_docs(docs):
        return "\n\n".join(doc.page_content for doc in docs)

    chain = (
        {"context": retriever | format_docs, "question": RunnablePassthrough()}
        | prompt
        | llm
        | StrOutputParser()
    )

    return chain


def main():
    # Example usage
    urls = [
        "https://example.com/page1",
        "https://example.com/page2",
    ]

    print("Loading documents...")
    docs = load_documents(urls)
    print(f"Loaded {len(docs)} documents")

    print("Splitting documents...")
    chunks = split_documents(docs)
    print(f"Created {len(chunks)} chunks")

    print("Creating vector store...")
    vectorstore = create_vectorstore(chunks)

    print("Building RAG chain...")
    chain = build_rag_chain(vectorstore)

    # Query
    question = "What is this about?"
    print(f"\nQuestion: {question}")
    answer = chain.invoke(question)
    print(f"Answer: {answer}")


if __name__ == "__main__":
    main()

Read the full file on GitHub · 602 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 602 lines · 21 tokens per session scan A 31e5ad9cc074

Subscribe to this mod's changes

new-rag is a command published in the GitHub repository Codeblockz/langchain-community-plugin (3 stars, last pushed 7mo ago), licensed Apache-2.0. It adds 21 tokens to every session and 3,455 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.