Prompt+RAG
Give your prompt a searchable memory, right in the graph
- final_prompt
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:
- It lists every
.txtfile inrag_docand offers them in therag_txtdropdown. - On first use of a file, it chunks the text into ~800-character pieces with 100 characters of overlap.
- 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. - It embeds your prompt, does a cosine top-k search, and splices the best chunks together separated by
---. - The index is cached (hashed by file content) in the pack's
.rag_indexfolder, 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
.txtfiles found inrag_doc. Ships withexample.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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| seed | INT | 00–999999 | — |
| rag_txt | COMBO | example.txt | 1 options: example.txt |
| prompt | STRING | Analyze the image. | — |
| use_rag | BOOLEAN | false | — |
| k | INT | 41–20 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| final_prompt | STRING | — |