Azure-Samples/rag-postgres-openai-python
A RAG app to ask questions about rows in a database table. Deployable on Azure Container Apps with PostgreSQL Flexible Server.
What it solves
This project provides a reference implementation for building a web-based chat application that can answer questions about data stored in a PostgreSQL database. It solves the challenge of combining structured database queries with unstructured natural language search to provide accurate answers based on private data.
How it works
The application uses a Retrieval-Augmented Generation (RAG) architecture. It converts user queries into vectors using the OpenAI embedding API and performs a hybrid search on PostgreSQL using the pgvector extension for vector search and standard full-text search, combining results via Reciprocal Rank Fusion (RRF). Additionally, it uses OpenAI function calling to translate natural language queries into SQL filter conditions (e.g., converting "Climbing gear cheaper than $30?" into a WHERE clause).
Who it’s for
Developers looking to implement RAG patterns using PostgreSQL as a vector store, specifically those targeting deployment on Azure using Container Apps and Azure OpenAI, though it also supports local development with Ollama.
Highlights
- Hybrid Search: Combines vector search and full-text search for better retrieval accuracy.
- SQL Translation: Uses LLM function calling to convert natural language into database filters.
- Azure Integration: Streamlined deployment via the Azure Developer CLI (
azd). - Cros-Platform Support: Compatible with Azure OpenAI, OpenAI.com, and local models via Ollama.
Related
- Project
- Project
- Project
- Project
- Project