RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /How-to
  5. /How to set up a local development AI stack with LangChain, Postgres, and Weaviate
HOW-TO · OPS

How to set up a local development AI stack with LangChain, Postgres, and Weaviate

advanced·35 min·By Fredoline Eruo
Target environment
Ubuntu 24.04 · Ollama 0.4.x
PREREQUISITES

Docker Compose, Python environment

What this does

This guide provisions a local development environment for building AI agents using LangChain, PostgreSQL (with pgvector) for structured data and vector storage, and Weaviate as a dedicated vector database for semantic search. Each component runs in Docker Compose with persistent volumes, and the Python environment connects to all services. This stack mirrors a production AI architecture at development scale.

Steps

  1. Create the project directory and Python virtual environment:

    mkdir ai-dev-stack && cd ai-dev-stack
    python3 -m venv .venv && source .venv/bin/activate
    pip install langchain langchain-core langchain-community pgvector psycopg2-binary weaviate-client
    
  2. Create docker-compose.yml with Postgres (pgvector) and Weaviate:

    version: "3.8"
    services:
      postgres:
        image: pgvector/pgvector:pg16
        environment:
          POSTGRES_USER: aiagent
          POSTGRES_PASSWORD: secret123
          POSTGRES_DB: ai_agents
        ports: ["5432:5432"]
        volumes: ["pgdata:/var/lib/postgresql/data"]
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U aiagent"]
          interval: 5s
      weaviate:
        image: semitechnologies/weaviate:1.25.0
        ports: ["8080:8080"]
        environment:
          AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: "true"
          PERSISTENCE_DATA_PATH: "/var/lib/weaviate"
          ENABLE_MODULES: "text2vec-transformers"
        volumes: ["weaviate_data:/var/lib/weaviate"]
    volumes:
      pgdata:
      weaviate_data:
    
  3. Start the services and verify they are healthy:

    docker compose up -d && docker compose ps
    

    Expected output: both services with status healthy.

  4. Initialize the pgvector extension in Postgres:

    docker compose exec postgres psql -U aiagent -d ai_agents -c "CREATE EXTENSION IF NOT EXISTS vector;"
    

    Expected output: CREATE EXTENSION.

  5. Configure LangChain to connect to both backends. Create config.py:

    PG_CONNECTION = "postgresql+psycopg2://aiagent:secret123@localhost:5432/ai_agents"
    WEAVIATE_URL = "http://localhost:8080"
    
  6. Initialize the Weaviate client and create a schema for document embeddings:

    import weaviate
    client = weaviate.connect_to_local(host="localhost", port=8080)
    client.collections.create(
        name="Documents",
        properties=[{"name": "content", "dataType": ["text"]}],
        vectorizer_config={"vectorizer": "text2vec-transformers"}
    )
    
  7. Initialize the LangChain Postgres vector store for conversation history:

    from langchain_community.vectorstores import PGVector
    from langchain_community.embeddings import OllamaEmbeddings
    
    embeddings = OllamaEmbeddings(model="nomic-embed-text")
    vectorstore = PGVector(
        connection_string=PG_CONNECTION,
        embedding_function=embeddings,
        collection_name="conversation_history",
    )
    
  8. Test the full pipeline: store a document in Weaviate, index conversation history in Postgres, and run a LangChain chain that queries both:

    doc_coll = client.collections.get("Documents")
    doc_coll.data.insert({"content": "Sample document for testing"})
    vectorstore.add_texts(["Conversation turn 1: User asked about deployment."])
    
    from langchain.chains import RetrievalQA
    weaviate_retriever = doc_coll.as_retriever()
    pg_retriever = vectorstore.as_retriever()
    # Combine retrievers in the chain
    

Verification

curl -s http://localhost:8080/v1/.well-known/ready | jq

Expected output: {} (Weaviate ready, HTTP 200).

Common failures

  • pgvector extension fails to create — ensure the Docker image is pgvector/pgvector:pg16, not the standard postgres:16 image which lacks the vector extension.
  • Weaviate schema creation hangs — the text2vec-transformers module downloads a model on first use. Wait for the download (visible in docker compose logs weaviate) before creating the collection.
  • LangChain cannot connect to Postgres — the PG_CONNECTION string must use psycopg2 (not psycopg2-binary) in the driver portion. Confirm connectivity with psql -h localhost -U aiagent -d ai_agents.

Related guides

  • Create a Docker Compose stack with vLLM, Redis, and Prometheus
  • Implement healthchecks and restart policies for AI containers
  • Set up a multi-service AI logging stack with Docker Compose
← All how-to guidesCourses →