How to set up a local development AI stack with LangChain, Postgres, and Weaviate
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
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-clientCreate
docker-compose.ymlwith 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:Start the services and verify they are healthy:
docker compose up -d && docker compose psExpected output: both services with status
healthy.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.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"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"} )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", )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 standardpostgres:16image which lacks the vector extension. - Weaviate schema creation hangs — the
text2vec-transformersmodule downloads a model on first use. Wait for the download (visible indocker compose logs weaviate) before creating the collection. - LangChain cannot connect to Postgres — the
PG_CONNECTIONstring must usepsycopg2(notpsycopg2-binary) in the driver portion. Confirm connectivity withpsql -h localhost -U aiagent -d ai_agents.