RAG Pipeline Code Explorer

The same pipeline — load, chunk, embed, retrieve, generate — in three frameworks. Click each to see the full code and what it costs you.

SynapseKit · 4 lines
LlamaIndex · 9 lines
LangChain · 13 lines
SynapseKit
Highest abstraction
1
Import lines
3
Functional lines
4
Total lines
1
Concepts to learn

Import

from synapsekit import RAG

Full pipeline (3 lines)

rag = RAG(model="llama-3.1-8b-instant", api_key=API_KEY, provider="groq")
rag.add(DOCUMENT)
answer = rag.ask_sync(QUERY)
Mental model
1 class, 2 methods
Chunking
Automatic (internal)
Vector store
Internal, no config
Provider switch
1 string parameter
✓ Advantage
Fastest path to a working pipeline. Provider switching is a single string change — no new packages, no new imports. Zero coupling between steps means zero wiring bugs.
✗ Trade-off
Internals are hidden. Custom chunking strategy, non-default retrieval scoring, or multi-stage pipelines require going outside the facade. Less transparent to engineers unfamiliar with the library.

Provider switch: OpenAI → Groq

# Before
rag = RAG(model="gpt-4o-mini", api_key=KEY, provider="openai")

# After — 1 line changed, no new packages
rag = RAG(model="llama-3.1-8b-instant", api_key=KEY, provider="groq")
LlamaIndex
Opinionated defaults
3
Import lines
6
Functional lines
9
Total lines
3
Concepts to learn

Imports

from llama_index.core import VectorStoreIndex, Document, Settings
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding

Full pipeline (6 lines)

Settings.llm         = OpenAI(model="gpt-4o-mini", api_key=API_KEY)
Settings.embed_model = OpenAIEmbedding(api_key=API_KEY)
index  = VectorStoreIndex.from_documents([Document(text=DOCUMENT)])
engine = index.as_query_engine(similarity_top_k=5)
answer = engine.query(QUERY)
print(answer)
Mental model
Settings + Index + Engine
Chunking
Automatic defaults
Vector store
In-memory (default)
Provider switch
New pip + new import + new class
✓ Advantage
Clean API with sensible defaults. Global Settings makes single-model pipelines concise. Easy to customise chunking, retrieval top-k, and storage backend without changing the overall pattern.
✗ Trade-off
Global Settings is a footgun in multi-model pipelines — different agents using different LLMs can silently inherit each other's config. Provider switching requires a new per-provider package install.

Provider switch: OpenAI → Groq

# Before
Settings.llm = OpenAI(model="gpt-4o-mini", api_key=OPENAI_KEY)

# After — 3 lines changed
# pip install llama-index-llms-groq
from llama_index.llms.groq import Groq
Settings.llm = Groq(model="llama-3.1-8b-instant", api_key=GROQ_KEY)
LangChain
Maximum control
5
Import lines
8
Functional lines
13
Total lines
5
Concepts to learn

Imports

from langchain_core.documents import Document
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from langchain.chains import RetrievalQA

Full pipeline (8 lines)

docs   = [Document(page_content=DOCUMENT)]
chunks = RecursiveCharacterTextSplitter(
             chunk_size=500, chunk_overlap=50
         ).split_documents(docs)
vs     = FAISS.from_documents(chunks, OpenAIEmbeddings(api_key=API_KEY))
chain  = RetrievalQA.from_chain_type(
             llm=ChatOpenAI(model="gpt-4o-mini", api_key=API_KEY),
             retriever=vs.as_retriever(search_kwargs={"k": 5})
         )
answer = chain.invoke({"query": QUERY})
print(answer["result"])
Mental model
5 independent components
Chunking
Explicit splitter object
Vector store
Explicit (FAISS, etc.)
Provider switch
New pip + new import + new class
✓ Advantage
Maximum control — every component is independently swappable. The pipeline is self-documenting: a new engineer can read the code and understand what's happening without knowing LangChain. Best fit for complex multi-step pipelines with custom logic between steps.
✗ Trade-off
Most lines, most concepts. Five separate objects to construct and wire together. Provider switching still requires a new package. The explicit wiring that makes it readable also makes it verbose.

Provider switch: OpenAI → Groq

# Before
ChatOpenAI(model="gpt-4o-mini", api_key=OPENAI_KEY)

# After — 3 lines changed
# pip install langchain-groq
from langchain_groq import ChatGroq
ChatGroq(model="llama-3.1-8b-instant", api_key=GROQ_KEY)
www.engineersofai.com · AI Letters #12