A hands-on guide using USGS, PostgreSQL, Qdrant, Ollama, LangChain, LangGraph, memory, tools, and observability.
In this tutorial, I build an application that combines two types of knowledge that are typically taught separately. On one hand, I have structured, changing data: the USGS public earthquake feed. On the other, a small document-based knowledge base on seismology. The application decides when to query PostgreSQL, when to retrieve documents from Qdrant, and when it needs both to respond.
The final result includes real-time ingestion, temporal versioning, local embeddings, a classic RAG, LangChain tools, an agent built on LangGraph, memory, optional traces in LangSmith, a Streamlit interface, and an explicit workflow that I can inspect in LangGraph Studio. Everything runs on local Ollama models.

The question guiding this project is:
What was the strongest earthquake in the last 24 hours, and what does its magnitude mean?
The first part requires querying and computing on real-world events. The second part requires educational knowledge. If I feed all the data to the model and expect it to figure it out, I’ll end up relying on a task for which an LLM isn’t particularly reliable. If I store the events as vector documents, I also won’t be able to correctly reconstruct which record was current at a past point in time. That’s why I’m separating responsibilities:
PostgreSQL stores events, revisions, and ingests.Qdrant stores chunks of educational documents.Ollama generates embeddings and responses without a paid API.LangChain provides prompts, tools, and the interface to the model.LangGraph executes the agent loop, its conditional paths, and persists its state.LangSmith lets me inspect traces when I choose to enable it.Streamlit brings all these capabilities together in a visual interface.<aside> 💡 What is RAG?
RAG (Retrieval-Augmented Generation) is a technique that allows a language model to search for relevant information in a knowledge base before generating a response, using that data as context to provide a more accurate answer.
In a nutshell:
RAG = Retrieve information + Generate a response based on that information.
</aside>
We need the following: