Skip to content

RAG with a built-in knowledge base, no vector DB ​

What you get: A question-answering workflow that retrieves from a knowledge base stored in L2M's own database, with no vector database and no API key.

Needs: No API key to start · Time: 10 minutes · Nodes: 5

A Question node holds the question. RAG Retrieve searches a built-in knowledge base for the three nearest chunks, a Prompt Template puts them into a grounded prompt, and an LLM node answers. The sample uses token-embedder, a hash-based demo embedder that needs no key (its search quality is poor), and the echo model. Echo returns the prompt it was given, which is useful here: the answer shows exactly what a real model would read. Swap both for real ones to get real answers.

Steps ​

  1. Download rag-knowledge-base-flow.json, or take it from the samples folder on GitHub.
  2. In the studio's workflow editor, import the file (see import and export).
  3. As an admin, create a knowledge base with the token-embedder and add a document, under Knowledge in the sidebar or with the API (below). Get its id (kb_...) from the create response or from GET /api/knowledge-bases; the Knowledge page does not show it.
  4. Open the RAG Retrieve (KB) node and replace <your-kb-id> with that id. Save.
  5. Run it, then change the question on the Question node and run it again.

How it works ​

Diagram of the RAG with Knowledge Base workflowRuns Question, then RAG Retrieve (KB), then Grounded Prompt, then LLM, then Output.Question (text_input)Questiontext_inputRAG Retrieve (KB) (rag_retrieve)RAG Retrieve (KB)rag_retrieveGrounded Prompt (prompt_template)Grounded Promptprompt_templateLLM (llm_call)LLMllm_callOutput (output)Outputoutput
Solid arrows are the order the steps run in. Dashed lines attach a chat model, memory, tools or workers to an agent; the agent uses them while it runs.
NodeTypeRole
Questiontext_inputStep in the run
RAG Retrieve (KB)rag_retrieveStep in the run
Grounded Promptprompt_templateStep in the run
LLMllm_callStep in the run
OutputoutputStep in the run

5 node types. Each type links to its config fields in the node reference.

Create a knowledge base with the API ​

bash
# An admin's API key, from Settings → Account → API Keys.
export L2M_API_KEY=ao_...

# Create a knowledge base. The response holds its id: kb_...
curl -X POST http://localhost:4000/api/knowledge-bases \
  -H "Authorization: Bearer $L2M_API_KEY" -H "Content-Type: application/json" \
  -d '{"name": "Helpdesk FAQ", "embedderId": "token-embedder", "embedderConfig": {}}'

# Load, chunk, embed and store a Markdown file in one call.
export KB_ID=kb_...   # the id from the response above
curl -X POST http://localhost:4000/api/knowledge-bases/$KB_ID/upload \
  -H "Authorization: Bearer $L2M_API_KEY" -H "Content-Type: application/json" \
  -d '{"filename": "helpdesk-faq.md", "sourceId": "helpdesk-faq-v1",
       "content": "# Helpdesk FAQ\n\n## Reset your password\nTo reset your password, open the sign-in page, choose Forgot password, and enter your work email. The reset link is valid for 30 minutes.\n\n## Change your billing plan\nAdmins can change the billing plan under Settings, then Billing. Changes apply from the next invoice.\n\n## Export your data\nGo to Settings, then Data, and choose Export. You get a ZIP file with one CSV per table.",
       "chunking": {"strategy": "recursive", "chunkSize": 300, "chunkOverlap": 0}}'

On our install the upload answered {"sourceId":"helpdesk-faq-v1","documentsLoaded":1,"chunksInserted":2,"dimensions":64}. The embedder you create the knowledge base with must match the embedderId on the RAG Retrieve node, or the question and the chunks are not compared in the same space.

What a run does ​

We ran the sample on a fresh install, against a knowledge base holding a short helpdesk FAQ (a password-reset section, a billing section and a data-export section, stored as 2 chunks):

  • RAG Retrieve returned both chunks, the password-reset chunk first (similarity 0.375, against 0.131 for the other), each with its chunkId, sourceId and score.
  • Grounded Prompt numbered them [1] and [2] under "Context:" and added the question.
  • LLM (echo) returned that whole prompt, prefixed with Echo: , and Output returned it as result.

Two things to know:

  • A missing id fails quietly. Run the sample without replacing <your-kb-id> and it still succeeds: retrieval returns no documents and the prompt's context is empty. If answers look ungrounded, check the retrieve node's documents first.
  • The template asks for chunk ids, but the context shows numbers. The prompt says "Cite the chunkId for every claim" while the context lists [1], [2]. For citations that resolve to their sources, use the citationInstructions the retrieve node emits and the citation tools in Knowledge bases.

Variant: retrieve from a connector ​

rag-flow.json loads documents from a Connector Source (Google Drive) on every run and retrieves from them in memory, with no knowledge base. As shipped it calls a local Ollama model (llama3.1). We ran it with the echo model and no Google credentials: the connector ran in demo-fallback mode and returned five built-in sample documents, and retrieval put the three closest to "How does MCP fit into an AI workflow builder?" into the prompt. Use a knowledge base when the documents should be ingested once and kept; use a connector for small sets that change between runs.

Make it yours ​

  • Use a real embedder (for example openai-embedder, with its key as a secret) for the knowledge base and the same embedderId on the node. A knowledge base keeps the vector size of its first chunks, so start a new one when you change embedders.
  • Replace the echo model with a real one on the LLM node.
  • Set searchMode to hybrid to add keyword (BM25) matches to vector search, and add a Rerank node for better ordering. See hybrid search.

Make it safer ​

These controls are optional; the recipe runs without them.

  • Retrieved documents are outside content: a document can carry instructions for the model. Content rules can check each retrieved document before it reaches the model.
  • Cap model spend with a budget once you switch to a paid model.

Further reading ​

This website (not the L2M product) uses Google Analytics, only after you accept cookies. Cookie settings