AI / LLM and RAG nodes
Call large language models from a graph and build retrieval-augmented
generation (RAG) pipelines — answering questions from your own documents.
Source: backend/core/nodes/ai/ai_nodes.py. Demo:
projects/demo_project/ai/rag_demo.weave.
Load Documents ─▶ Split Text ─▶ Build Vector Index ─▶ Retrieve ─▶ Format Context ─┐
▲ ▼
question ───────────▶ Prompt Template ─▶ LLM Chat
Nodes
| Node | Category | What it does |
|---|---|---|
| LLM Chat | AI / LLM | Sends a prompt (+ optional system text) to OpenAI, Anthropic Claude, Google Gemini, Ollama or an OpenAI-compatible server; outputs the reply. Model blank = the provider's default. |
| Prompt Template | AI / LLM | Fills {question}, {context} and any {key} from a values dict. Unknown placeholders are left as written. |
| Load Documents | AI / RAG | Reads text files in a folder matching a glob (**/*.md, **/*.txt). |
| Split Text | AI / RAG | Chunks documents by paragraphs, markdown sections or fixed character windows, with overlap. |
| Embed Text | AI / RAG | Texts → an (n, d) array of unit vectors (for clustering / plotting with the ML nodes). |
| Build Vector Index | AI / RAG | Indexes chunks for similarity search; a plain dict (method, model, chunks, matrix, vectorizer). |
| Retrieve | AI / RAG | Top-k chunks for a query by cosine similarity. |
| Format Context | AI / RAG | Numbers and labels retrieved chunks ([1] source) into one context string, up to a character limit. |
Providers and keys
LLM Chat uses the same providers and .env keys as the chat assistant:
OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, OLLAMA_HOST
(optional) and OPENAI_COMPATIBLE_BASE_URL / _API_KEY / _MODEL. Keys are
never stored in the graph, and exported scripts read them from the
environment (or a .env found from the working directory). Every run of an
LLM Chat node is a real, possibly billed, API call.
The node uses a small self-contained client rather than the chat panel's provider classes because exported scripts must run without EdgeWeave; the environment variables and default models are the same.
Embedding methods
| Method | Needs | Matches on |
|---|---|---|
tfidf (default) | nothing — scikit-learn, offline, deterministic | shared words |
ollama | Ollama running + ollama pull nomic-embed-text (~270 MB) | meaning |
openai | OPENAI_API_KEY (text-embedding-3-small) | meaning |
auto | — | Ollama's nomic-embed-text if it is pulled, otherwise TF-IDF |
Chat-only Ollama models (e.g. gemma3) can't produce embeddings; the node
says so and suggests an embedding model.
Python export
Every node exports: the same ai_* functions that run in the app are copied
into the script, so export and runtime can't drift. Relative folders in Load
Documents resolve from the working directory when the script runs (in the
app they also fall back to the EdgeWeave root and the active project).
While building this family we fixed an exporter bug: {tokens} in a node's
expr were filled by chained str.replace, so a field value that itself
contained {name} text (a Prompt Template's {context}) was rewritten by a
later substitution. PythonGenerator._expand_expr now substitutes all
tokens in a single pass.