How langchain-ai/langconnect works
Project type and purpose
• LangConnect is a single microservice full‐stack application (backend‐only) offering a REST API for collection and document management plus semantic search via vector embeddings.
• Key indicators: “FastAPI‐based REST API,” “PostgreSQL with pgvector,” “LangChain” in README and the presence of api/, services/, database/ folders.
File structure
• Top‐level executables/configuration: Dockerfile, docker‐compose.yml, Makefile, .env.example
• Application code under langconnect/:
• __main__.py & server.py (entrypoint, ASGI server)
• api/ (REST endpoints/controllers: collections.py, documents.py)
• services/ (business logic: document_processor.py)
• database/ (storage adapters: connection.py, collections.py)
• models/ (Pydantic models for Collection, Document)
• auth.py, config.py (cross‐cutting concerns)
• tests/ (unit tests for API and imports)
README for additional insights
• Tech stack: FastAPI, LangChain, PostgreSQL+pgvector, Docker
• Runtime: one Docker service for the API, one for Postgres
• Exposed ports: 8080 for API docs & health
a. Clients and API Gateway
• External clients (browser, curl, Postman) calling HTTP endpoints (port 8080)
b. FastAPI service
• HTTP layer (uvicorn ASGI server in server.py)
• API controllers (langconnect/api/*.py)
• Auth and config (auth.py, config.py)
c. Business logic / Services
• DocumentProcessor (langconnect/services/document_processor.py) orchestrating:
• Content ingestion
• Embedding generation via LangChain (calls to LLM or embedding API)
• Vector storage operations
d. Persistence layer
• PostgreSQL with pgvector extension (containerized)
• DB adapter code (langconnect/database/connection.py, collections.py)
e. External dependencies
• LangChain library (for vector embedding generation and RAG flow)
• Docker / Docker Compose (for deployment orchestration)
Relationships and data flow
• Clients → HTTP POST/GET → FastAPI controllers
• Controllers → Business services →
• DocumentProcessor invokes LangChain embedding API (external HTTP/gRPC calls)
• Database adapter issues SQL commands to Postgres + pgvector
• Database → returns data (records + vectors) → service → controller → client
Architectural patterns / principles
• Layered architecture (Controller → Service → Data Access)
• Dependency injection via config.py for DB connection and environment variables
• Separation of concerns: models, services, API, and database modules
• Containerization for reproducibility and isolation
Technologies / frameworks to call out
• FastAPI (web framework)
• Uvicorn (ASGI server)
• LangChain (LLM orchestration)
• PostgreSQL + pgvector (vector store)
• Docker + Docker Compose (containers, networking)
• Pydantic (data validation models)