Skip to content

elandy/rag_langchain

Repository files navigation

RAG with LangChain

A production-oriented Retrieval-Augmented Generation (RAG) system built using LangChain and Clean Architecture.

Unlike my previous RAG implementation—which was built entirely from scratch without any framework—this project explores how to build a maintainable and extensible RAG using LangChain while keeping framework-specific code isolated from the core domain.

Goals

  • Clean Architecture
  • Framework-agnostic domain layer
  • Modular ingestion pipeline
  • Local-first stack
  • Production-oriented design
  • Easy experimentation with retrieval techniques

Current Architecture

                PDF
                 │
          PDF Loader
                 │
        Document Processors
                 │
        Recursive Chunker
                 │
          Ollama Embeddings
                 │
      PostgreSQL + pgvector
                 │
──────────── Retrieval ────────────

Question
     │
PGVector Retriever
     │
Cross-Encoder Reranker
     │
Relevant Context
     │
Prompt Builder
     │
Llama 3.1 (Ollama)
     │
Answer

Project Structure

rag/
│
├── app/
│   ├── api/
│   ├── application/
│   ├── config/
│   ├── domain/
│   └── infrastructure/
│
├── evaluation/
├── tests/
├── main.py
└── pyproject.toml

Tech Stack

LLM

  • Ollama
  • Llama 3.1 8B

Embeddings

  • nomic-embed-text

Vector Database

  • PostgreSQL
  • pgvector

Framework

  • LangChain

Retrieval

  • Dense Retrieval
  • Cross-Encoder Reranking

Evaluation

  • DeepEval
  • RAGAS

Current Features

  • PDF ingestion
  • Recursive text chunking
  • Custom document processing pipeline
  • Ollama embeddings
  • PostgreSQL + pgvector storage
  • Dense semantic retrieval
  • Cross-encoder reranking
  • Modular retrieval and generation services
  • Clean Architecture

Planned Features

  • Hybrid retrieval (Dense + BM25)
  • Metadata filtering
  • Context compression
  • Query rewriting
  • Multi-query retrieval
  • Reciprocal Rank Fusion (RRF)
  • LangGraph workflows
  • Streaming responses
  • Source citations
  • FastAPI API
  • LangSmith tracing
  • Comprehensive evaluation benchmarks

Design Principles

  • Keep business logic independent of LangChain.
  • Depend on interfaces instead of implementations.
  • Isolate infrastructure components.
  • Make every component replaceable.
  • Prefer composition over inheritance.

Related Project

This repository is the LangChain counterpart to my previous project, where every RAG component—including embeddings, vector search, prompt orchestration, and retrieval—was implemented manually without using LangChain.

About

A modular Retrieval-Augmented Generation (RAG) system built with LangChain, Clean Architecture, PostgreSQL/pgvector, Ollama, and local models.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages