Cortex Core vs LangGraph
00 Overview
One app, built twice. Read this first, then step through the files in order.

Cortex is a chatbot with two jobs: an agent that remembers past conversations and can search the web, and a RAG pipeline that answers questions from uploaded PDFs. cortex-core builds everything by hand on the raw OpenAI, transformers and chromadb libraries. cortex-langgraph rebuilds the same app on LangChain components and LangGraph graphs, keeping prompts, defaults and behavior the same so the two can be compared fairly.

The pattern to look for
Almost every change is one of two moves. LangChain replaces a hand-written interface (model, embeddings, vector store, prompt, splitter) with a standard one that every provider implements. LangGraph replaces hand-written control flow (the tool loop, the RAG steps, the fallback policy) with a graph of nodes and edges you can see, bound and trace.

What replaced what

cortex-core (hand-written)cortex-langgraphTab
BaseLLM + OpenAIModel / LocalHFModel→BaseChatModel (ChatOpenAI, AzureChatOpenAI, ChatHuggingFace)model.py
Embedder + hand-written retry loop→Embeddings + CacheBackedEmbeddingsembedding.py
PromptBuilder f-strings→ChatPromptTemplate / PromptTemplateprompt_builder.py
while True: tool loop→StateGraph + ToolNode + tools_conditionagentic_chatbot.py
TOOLS JSON schemas + if/elif dispatch→@tool functionstools.py
RAGPipeline.answer(), three calls in a row→RAG StateGraph with a policy branchretrieval.py
select_context() fallback policy→Conditional edge _route_after_rerank()orchestrator.py
VectorStoreBase + two backends→VectorStore (Chroma, AzureSearch)vector_store.py
Fixed-window Chunker→RecursiveCharacterTextSplitterchunk.py
Hand-walked Docling model→DoclingLoaderpdf_digest.py
Manual torch cross-encoder→BaseCrossEncoder over sentence-transformerscross_encoder.py
RetrievedChunk / ReRankedChunk dataclasses→Document + metadatainterface.py
Token usage never reported→AIMessage.usage_metadata on every callchatbot/__init__.py

How to read each tab

Each tab starts with a short note: what the file does, how each project does it, and why the change matters. Below it is an aligned side-by-side diff: cortex-core on the left, cortex-langgraph on the right. Red rows exist only on the left or were rewritten, green rows are new on the right, and white rows are identical. Turn on Hide unchanged lines to see only the differences.

17
files changed
18
files identical
3
files only in cortex-core
1
file only in cortex-langgraph

Unchanged between the two

The whole API layer (FastAPI routes, controller, rate limiter, metrics), the data models, cost calculation, web search and the Redis / SQLite memory are byte-for-byte identical. The framework swap only touched the model, retrieval and agent code.

  • scripts/index_cli.py
  • src/api/controller.py
  • src/api/main.py
  • src/api/metrics.py
  • src/api/ratelimiter.py
  • src/api/router.py
  • src/api/service.py
  • src/business/core/cost.py
  • src/business/core/live_data.py
  • src/business/rag/re_ranker/__init__.py
  • src/business/rag/re_ranker/config.py
  • src/config/config.yml
  • src/database/database.py
  • src/database/dto.py
  • src/memory/chat_history_manager.py
  • src/memory/redis_memory.py
  • src/memory/responsecache.py
  • src/utils/config.py

Also only in cortex-core: re_ranker/gating.py, an empty placeholder file.

New dependencies in cortex-langgraph

langchainlangchain-corelanggraphlanggraph-prebuiltlangchain-openailangchain-huggingfacelangchain-chromalangchain-azure-ailangchain-doclinglangchain-text-splitterslangchain-classiclangsmith