The AzureKnowledgeBase class provides a was to access documents in Azure Knowledgebase with Azure Search functionality. The class facilitates document indexing, searching, and topic-based organization. In this implementation, Azure Search serves as the backend for indexing and querying documents, while an embedding model and an LLM client assist in document categorization and topic summarization.

Dependencies

The following external dependencies are required:

uv add "trusttest[rag-azure]"

Usage Example

import os

from dotenv import load_dotenv

from trusttest.catalog import FunctionalRAGScenario
from trusttest.knowledge_base.azure_search import AzureKnowledgeBase
from trusttest.models.testing import DummyEndpoint

load_dotenv(override=True)

url = os.getenv("UPSTASH_URL")
token = os.getenv("UPSTASH_TOKEN")

knowledge_base = AzureKnowledgeBase(
    service_endpoint=os.getenv("AZURE_SEARCH_SERVICE_ENDPOINT"),
    key=os.getenv("AZURE_SEARCH_KEY"),
    index_name=os.getenv("AZURE_SEARCH_INDEX_NAME"),
    fields_mapping={"content": "chunk", "id": "chunk_id"},
    language="Spanish",
)

rag_test = FunctionalRAGScenario(
    model=DummyEndpoint(), knowledge_base=knowledge_base, num_questions=2
)

test_set = rag_test.probe.get_test_set()
results = rag_test.eval.evaluate(test_set)
results.display_summary()