ComfyUI Node

Prompt+RAG

Give your prompt a searchable memory, right in the graph

By gpdev-Pilcothink·Created 11 months ago·Updated 3 months ago· 2
Prompt+RAG
    • final_prompt
    seed0
    rag_txtexample.txt
    promptAnalyze the image.
    use_ragfalse
    k4

    Pilcothink-RAG (displayed as "Prompt+RAG") is the pack's attempt to give your ComfyUI LLM workflow a memory. It's a prompt-composition node: you give it a question, it searches a local text library, and it hands back a single string that wraps the relevant passages in [CONTEXT] tags so the language model can answer with actual knowledge instead of vibes. RAG is normally a whole separate service; here it's a node in your graph.

    The intended flow is simple. Drop plain-text files into the pack's rag_doc folder, wire this node's final_prompt output into your SLM or vision generator's user_prompt, and the model gets the retrieved context before it ever sees your question.

    How it works

    The pipeline is conventional retrieval-augmented generation, stripped to the essentials:

    1. It lists every .txt file in rag_doc and offers them in the rag_txt dropdown.
    2. On first use of a file, it chunks the text into ~800-character pieces with 100 characters of overlap.
    3. It embeds each chunk - preferring sentence-transformers/all-MiniLM-L6-v2, which it runs on CPU, with a TF-IDF fallback if that import fails, and a crude letter-frequency fallback after that.
    4. It embeds your prompt, does a cosine top-k search, and splices the best chunks together separated by ---.
    5. The index is cached (hashed by file content) in the pack's .rag_index folder, so re-runs don't re-embed.

    If use_rag is off, or the file list is empty, the node is a pure passthrough: your prompt goes out unchanged.

    The inputs that matter

    • rag_txt - dropdown of the .txt files found in rag_doc. Ships with example.txt.
    • use_rag - the master switch. Default off; you must flip it on or the node does nothing.
    • prompt - your actual question. Defaults to "Analyze the image." since the pack pairs this with its vision generator.
    • k - how many chunks get retrieved, 1–20, default 4. Higher means more context but more noise.
    • seed - accepted but not used in any meaningful way; it's there for graph consistency.

    The single output, final_prompt, is a STRING you feed to a generator's prompt input.

    Install

    It's part of the comfyui_pilcothink_VisionSLM pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/gpdev-Pilcothink/comfyui_pilcothink_VisionSLM
    

    Restart, or install via ComfyUI Manager (search comfyui_pilcothink_VisionSLM). The RAG path needs sentence-transformers and faiss-cpu from the pack's requirements - both are in there, though this implementation only actually needs sentence-transformers.

    Gotchas

    Your documents go in rag_doc, inside the custom node folder, not in ComfyUI's models or input directory - easy to miss and a common cause of the dropdown showing only example.txt. Also note the README's guidance that RAG data must be .txt; anything else won't appear in the dropdown.

    Two honest caveats. First, the retrieval quality is basic - 800-character chunking with no sentence awareness means mid-sentence splits, and the embedding model is the smallest one on the shelf. Fine for a knowledge base of a few documents, hopeless for serious search over a large corpus. Second, this is a brand-new pack with no community mileage; if RAG is the whole point of your project, a purpose-built RAG pack with a track record is a safer bet. If you just want a lightweight "make my SLM know about my notes" node, this does it.

    CategoryPilcothink/RAG_Prompt

    Inputs (5)

    NameTypeDefaultDescription
    seedINT00–999999
    rag_txtCOMBOexample.txt1 options: example.txt
    promptSTRINGAnalyze the image.
    use_ragBOOLEANfalse
    kINT41–20

    Outputs (1)

    NameTypeDescription
    final_promptSTRING