This demo shows a minimal RAG pipeline using an ASP.NET Web API, PostgreSQL, pgvector extension, and Azure Foundry client. You can read more about this demo here: https://agentic-ai.info/implementing-rag-with-azure-foundry-net-backend-and-postgresql-vector-database/
Quick start:
- Build and start the stack:
docker compose up --build- Create an embedding (or skip and go to Point 4. Embed a local file):
curl -X POST http://localhost:5001/embeddings \
-H 'Content-Type: application/json' \
-d '{"text":"Hello from demo","metadata":{"source":"sample"}}'- Query:
curl -X POST http://localhost:5001/query \
-H 'Content-Type: application/json' \
-d '{"question":"What is Hello from demo?"}'- Embed a local file (use the demo text provided in
demo-data.txt):
python3 scripts/embed_file.py scripts/demo-data.txt --source demo-dataOptional arguments:
python3 scripts/embed_file.py scripts/demo-data.txt --chunk-size 1200 --overlap 150 --api-base-url http://localhost:5001 --source demo-dataExample queries (after embedding demo-data.txt):
curl -X POST http://localhost:5001/query \
-H 'Content-Type: application/json' \
-d '{"question":"Which city did the narrator visit after Lisbon?"}'curl -X POST http://localhost:5001/query \
-H 'Content-Type: application/json' \
-d '{"question":"What are the best month for travel?"}'Notes:
- Configure Azure credentials in
.env(copy.env.templateas a starting point). The API will fail to start if any of the three required variables (AZURE_FOUNDRY_API_KEY,AZURE_FOUNDRY_ENDPOINT,AZURE_FOUNDRY_EMBEDDINGS_ENDPOINT) are missing. - Vector search uses the
pgvectorextension with avector(1536)column, matching thetext-embedding-ada-002/text-embedding-3-smalloutput dimension. If you use different embedding models the db init script needs to be adjusted.