{"slug": "rag-in-10-lines-no-vector-database-no-pip-install", "title": "📚 RAG in ~10 Lines — No Vector Database, No pip install", "summary": "Pipe, a pipeline-native language, now supports retrieval-augmented generation (RAG) in about 10 lines of code without a vector database, framework, or external dependencies, according to a blog post in the 'Pipe in 30 Lines' series. The implementation uses built-in primitives `embed_batch`, `nearest`, and `ask` to vectorize documents, find top matches by cosine similarity, and answer with retrieved context, working with any provider such as DeepSeek, OpenAI, Anthropic, or Ollama. The post claims the equivalent Python and LangChain pipeline is roughly 80 lines across SDKs, while Pipe achieves it in a dozen lines with a single ~7 MB binary.", "body_md": "[← All posts← Alle Beiträge](../blog.html)\n\n# 📚 RAG in ~10 Lines — No Vector Database, No `pip install`\n\n**Semantic search and retrieval-augmented generation without a vector DB, a framework, or a single dependency.**\n\n> **Part of the *Pipe in 30 Lines* series:** [Self-healing code](tutorial-self-healing.html) · [Parallel LLM calls](tutorial-parallel.html) · [Your first MCP server](tutorial-first-mcp-server.html)\n\nRAG usually means a stack: a vector database, an embedding SDK, a retrieval library, and glue code to hold it together. Pipe collapses that into language primitives. `embed_batch`\n\nvectorizes your documents, `nearest`\n\nfinds the top matches by *meaning*, and `ask`\n\nanswers with the retrieved context — all in one binary, zero imports.\n\n```\nai_provider \"deepseek\"\n\ndocs: [\"Pipe is a pipeline-native language where data flows top to bottom.\", \"The bytecode VM runs compiled programs about 7x faster than the tree-walker.\", \"Built-in MCP lets Pipe expose its own tools or consume any stdio MCP server.\", \"Sandbox profiles restrict exec, write_file, and http_get in one declarative block.\", \"One ~7 MB binary, zero dependencies, on Linux, macOS, Windows, or the browser.\"]\n\nvectors: embed_batch docs        -- 1. vectorize once\nquestion: \"What makes the VM fast?\"\nq_vec: embed question            -- 2. embed the query\ntop: nearest q_vec vectors 2     -- 3. top-k by similarity\n\ncontext: \"\"\nfor idx in top\n    context: context ++ (at docs idx) ++ \"\\n---\\n\"\n\nask (\"Context:\\n\" ++ context ++ \"\\nQuestion: \" ++ question)\n    > print\n```\n\nWhat happens here:\n\nturns every document into a vector in one call — no vector DB to install, no index to configure.`embed_batch`\n\nreturns the *indices* of the most relevant documents by cosine similarity. Meaning, not keywords.`nearest`\n\n- The top matches are stitched into a context block, and\nanswers grounded in it — classic RAG.`ask`\n\nIn Python + LangChain the same pipeline is roughly 80 lines across SDKs. In Pipe it's a dozen, and it works with **every provider**: swap `\"deepseek\"`\n\nfor `\"openai\"`\n\n, `\"anthropic\"`\n\n, or `\"ollama\"`\n\nand nothing else changes.\n\nWant the full version with a web UI, SQLite persistence, and a `/search`\n\nAPI? See [ examples/rag_knowledge_base.pipe](https://github.com/MachuraHarry/pipe/blob/master/examples/rag_knowledge_base.pipe) — or run the minimal version above with\n\n`export DEEPSEEK_API_KEY=... && pipe examples/blog_rag.pipe`\n\n.# 📚 RAG in ~10 Zeilen — ohne Vektor-DB, ohne `pip install`\n\n**Semantische Suche und RAG ohne Vektor-DB, ohne Framework und ohne eine einzige Abhängigkeit.**\n\n> **Teil der Serie *Pipe in 30 Lines*:** [Selbstheilender Code](tutorial-self-healing.html) · [Parallele LLM-Calls](tutorial-parallel.html) · [Dein erster MCP-Server](tutorial-first-mcp-server.html)\n\nRAG bedeutet sonst einen ganzen Stack: eine Vektor-DB, ein Embedding-SDK, eine Retrieval-Bibliothek und Kleber-Code. Pipe reduziert das auf Sprach-Primitives. `embed_batch`\n\nvektorisiert deine Dokumente, `nearest`\n\nfindet die besten Treffer *nach Bedeutung*, und `ask`\n\nantwortet mit dem gelieferten Kontext — alles in einer Binary, null Imports.\n\n```\nai_provider \"deepseek\"\n\ndocs: [\"Pipe ist eine pipeline-native Sprache, in der Daten von oben nach unten fließen.\", \"Die Bytecode-VM führt Programme etwa 7x schneller aus als der Tree-Walker.\", \"Eingebautes MCP: Pipe stellt eigene Tools bereit oder nutzt jeden stdio-MCP-Server.\", \"Sandbox-Profile sperren exec, write_file und http_get in einem deklarativen Block.\", \"Eine ~7-MB-Binary, null Abhängigkeiten, auf Linux, macOS, Windows oder im Browser.\"]\n\nvectors: embed_batch docs        -- 1. einmal vektorisieren\nquestion: \"Was macht die VM schnell?\"\nq_vec: embed question            -- 2. Query einbetten\ntop: nearest q_vec vectors 2     -- 3. Top-K nach Ähnlichkeit\n\ncontext: \"\"\nfor idx in top\n    context: context ++ (at docs idx) ++ \"\\n---\\n\"\n\nask (\"Context:\\n\" ++ context ++ \"\\nQuestion: \" ++ question)\n    > print\n```\n\nWas hier passiert:\n\nverwandelt jedes Dokument in einen Vektor — kein`embed_batch`\n\n`pip install`\n\n, keine Vektor-DB, keine Index-Konfiguration.liefert die *Indizes* der relevantesten Dokumente per Kosinus-Ähnlichkeit. Bedeutung statt Keywords.`nearest`\n\n- Die Treffer werden zu einem Kontext-Block verbunden und\nantwortet darauf — klassisches RAG.`ask`\n\nIn Python + LangChain ist dieselbe Pipeline ~80 Zeilen über mehrere SDKs. In Pipe sind es ein Dutzend — und es funktioniert mit **jedem Provider**: Tausche `\"deepseek\"`\n\ngegen `\"openai\"`\n\n, `\"anthropic\"`\n\noder `\"ollama\"`\n\n, sonst ändert sich nichts.\n\nDie Vollversion mit Web-UI, SQLite-Persistenz und `/search`\n\n-API? Siehe [ examples/rag_knowledge_base.pipe](https://github.com/MachuraHarry/pipe/blob/master/examples/rag_knowledge_base.pipe) — oder starte die Minimalversion oben mit\n\n`export DEEPSEEK_API_KEY=... && pipe examples/blog_rag.pipe`\n\n.", "url": "https://wpnews.pro/news/rag-in-10-lines-no-vector-database-no-pip-install", "canonical_source": "https://pipe-lang.com/blog/tutorial-local-rag.html", "published_at": "2026-08-14 07:42:04.333733+00:00", "updated_at": "2026-08-14 07:42:06.668681+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "natural-language-processing", "generative-ai", "developer-tools"], "entities": ["Pipe", "DeepSeek", "OpenAI", "Anthropic", "Ollama", "LangChain", "Python"], "alternates": {"html": "https://wpnews.pro/news/rag-in-10-lines-no-vector-database-no-pip-install", "markdown": "https://wpnews.pro/news/rag-in-10-lines-no-vector-database-no-pip-install.md", "text": "https://wpnews.pro/news/rag-in-10-lines-no-vector-database-no-pip-install.txt", "jsonld": "https://wpnews.pro/news/rag-in-10-lines-no-vector-database-no-pip-install.jsonld"}}