azure_rag

command
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 11 Imported by: 0

README

Azure OpenAI — RAG (Retrieval-Augmented Generation)

End-to-end RAG on Azure OpenAI: embed documents with an Azure embeddings deployment, retrieve the most relevant ones for a question, and feed them as grounding context into an Azure chat completion.

What it demonstrates

  • model.NewAzureOpenAIEmbeddingsWithConfig as a model.EmbeddingsProvider
  • knowledge.NewVectorKnowledge — AddDocuments + Load to index, Search to retrieve top-k
  • A self-contained in-memory storage.VectorStore (MemoryVectorStore) using cosine similarity. Chronos has no built-in in-memory vector store, so this file doubles as a reference implementation of the storage.VectorStore interface (CreateCollection, Upsert, Search, Delete, Close)
  • Grounded answering: retrieved documents are injected as context with an instruction to answer only from that context

Run

This example needs two deployments — one chat and one embeddings:

export AZURE_OPENAI_API_KEY=<your-azure-api-key>
export AZURE_OPENAI_ENDPOINT=https://<your-resource>.openai.azure.com
export AZURE_OPENAI_DEPLOYMENT=<your-chat-deployment>             # e.g. gpt-4o-mini
export AZURE_OPENAI_EMBED_DEPLOYMENT=<your-embeddings-deployment> # e.g. text-embedding-3-small
export AZURE_OPENAI_API_VERSION=2024-10-21

go run ./examples/azure_rag/main.go

embedDimension in main.go is set to 1536 (text-embedding-3-small); change it to match your embeddings deployment (e.g. 3072 for text-embedding-3-large).

Without AZURE_OPENAI_API_KEY the example prints the required variables and exits 0 — no network call.

Tests

main_test.go is fully offline: it tests MemoryVectorStore (upsert/replace, delete, top-k) and cosineSimilarity ranking with tiny deterministic vectors. It never contacts Azure.

go test ./examples/azure_rag/...

See also: examples/azure (chat/streaming) and examples/azure_tools (tool calling).

Documentation

Overview

Azure OpenAI RAG (retrieval-augmented generation) example for Chronos.

This example shows an end-to-end RAG flow on Azure OpenAI:

  1. Build a small self-contained in-memory VectorStore (cosine similarity). Chronos ships production vector adapters (e.g. Qdrant), but there is no built-in in-memory store — so this file doubles as a reference for how to implement the storage.VectorStore interface.
  2. Wrap it in a knowledge.VectorKnowledge that embeds documents with an Azure OpenAI embeddings deployment (model.NewAzureOpenAIEmbeddings...).
  3. Load a few sample documents.
  4. Answer a question by retrieving the most relevant documents and feeding them as grounding context into an Azure chat completion.

Prerequisites:

  • An Azure OpenAI resource with BOTH a chat deployment (e.g. gpt-4o-mini) and an embeddings deployment (e.g. text-embedding-3-small)
  • Go 1.24+

Set the following environment variables before running:

export AZURE_OPENAI_API_KEY=<your-azure-api-key>
export AZURE_OPENAI_ENDPOINT=https://<your-resource>.openai.azure.com
export AZURE_OPENAI_DEPLOYMENT=<your-chat-deployment>            # chat
export AZURE_OPENAI_EMBED_DEPLOYMENT=<your-embeddings-deployment> # embeddings
export AZURE_OPENAI_API_VERSION=2024-10-21

Run:

go run ./examples/azure_rag/main.go

If AZURE_OPENAI_API_KEY is not set the example prints the required variables and exits cleanly (0) without making any network call. The in-memory VectorStore itself is exercised offline by main_test.go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL