How to Harness Retrieval-Augmented Generation (RAG) to unlock Conversational-style Pricing Intelligence
Praveen Orvakanti
Principal Architect - Data & Analytics | Data Engineering & BI Leader | Driving Strategic Business Decisions | Microsoft Azure Certified | Udacity Certified
This article explores how RAG, together with Azure OpenAI and Azure AI Search, can transform the way we query and extract insights from data — especially where traditional methods rely heavily on dashboards and manual queries. With RAG, we turn this on its head by allowing AI-driven conversational interfaces to answer questions directly from structured/textual data.
Imagine you’re a fan of J.R.R. Tolkien’s world, specifically The Rings of Power — and your fascination with this fantasy has led you to explore how legendary metals like Mithril would be priced. That’s how I turned a real-world problem in my work at a manufacturing company into an exciting, hands-on exploration of Retrieval-Augmented Generation (RAG) to gain business insights from structured data. While the actual problem I’m solving revolves around pricing transparency for steel products, we’re diving into this example with Mithril to explain how this cutting-edge technology can work across industries.
For those unfamiliar, Mithril is an incredibly powerful, valuable and rare metal in Tolkien’s lore. As a fan of The Rings of Power and a data enthusiast, I created a dataset inspired by Tolkien’s world to simulate real-world pricing dynamics. But you could easily imagine this dataset being applied to more tangible commodities like steel, oil, or financial data.
Problem Statement
Pricing transparency and quick decision-making are critical to maintaining a competitive edge in today's rapidly evolving data landscape. Stakeholders often need to understand why a product is priced a certain way or how market conditions and customer demand affect pricing. This often involves complex manual data aggregation and ad-hoc analyses, resulting in delays.
But what if we could automate this process using cutting-edge AI to get real-time insights?
To explain this, I built a fake dataset revolving around hypothetical commodity, Mithril, inspired by The Rings of Power. Imagine Mithril being traded across Middle-Earth, sourced from mines in Khazad-d?m, and sold to clans such as Men, Elves, and Orcs. The dataset includes CRM data with offers, orders, delivery details, dates, and pricing information along with some macroeconomic indicators such as mine capacity, demand, and supply — creating a perfect playground for testing a RAG-based AI solution.
Expected Benefits
The Data: CRM and Customer Data
We structured the data into two datasets: CRM data representing orders of Mithril and Customer data representing buyers. These datasets serve as our foundation for extracting insights, and you’ll see how RAG allows us to answer complex business questions based on this structured data.
What Can You Ask?
This is where it gets exciting — imagine being able to ask real questions directly about this structured data.
Here are some sample questions and answers:
The AI platform answers these questions by parsing the data, generating insights that normally would require complex queries or pre-built dashboards. This is the real magic of using a RAG-based system.
What is RAG, and Why Use It?
Retrieval-Augmented Generation (RAG) is a powerful framework that combines the strengths of two key components: information retrieval and natural language generation. Instead of relying solely on a large language model’s (LLM’s) pre-trained knowledge, RAG enhances responses by pulling in real-time, external data sources.
This approach helps to address some limitations of LLM’s:
领英推荐
In our case, we use Azure AI Search as the external data source, which indexes structured data (like pricing, demand, and customer information) and retrieves the most relevant documents based on user queries. Once the relevant data is retrieved, it is passed to a large language model — such as GPT-4o — which then generates a highly contextual, accurate, and insightful response.
RAG is particularly useful in scenarios where:
By using RAG, we ensure that the pricing intelligence platform doesn’t just rely on generic model knowledge but combines it with real-time, structured data for contextually rich answers.
System Architecture: The Workflow Behind the Curtain
Our system architecture is built around a simple yet powerful workflow:
Here’s a simple architecture diagram to explain how these pieces fit together:
Key Steps in Building the Solution
In this section, we will walk through the critical steps required to build a fully functional RAG-based pricing intelligence platform using Azure OpenAI and Azure AI Search. The journey starts with setting up the core services — OpenAI for generating natural language responses and Azure AI Search for indexing structured data. From there, we’ll break down our data into manageable chunks, upload it, and integrate the pieces to ensure smooth retrieval and generation of responses based on user queries.
Each of these steps is crucial in enabling the platform to handle large datasets, ensure scalability, and deliver real-time, insightful answers to complex pricing-related questions.
def create_customer_index(customer_index_name, search_index_client):
fields = [
SimpleField(
name="id",
type=SearchFieldDataType.String,
key=True,
sortable=True,
filterable=True,
facetable=True,
),
SearchField(name="CustomerID", type=SearchFieldDataType.String, sortable=True, filterable=True,
facetable=True),
SearchField(name="Name", type=SearchFieldDataType.String),
SearchField(name="Region", type=SearchFieldDataType.String, sortable=True, filterable=True,
facetable=True),
SearchField(name="Realm", type=SearchFieldDataType.String, filterable=True),
SearchField(name="Clan", type=SearchFieldDataType.String, filterable=True),
SearchField(name="Contact", type=SearchFieldDataType.String),
SearchField(name="GeopoliticalIndex", type=SearchFieldDataType.Double, filterable=True),
SearchField(name="EconomicHealthIndex", type=SearchFieldDataType.Double, filterable=True),
SearchField(name="PreferredSeason", type=SearchFieldDataType.String, filterable=True),
SearchField(name="TransportationCostUSD", type=SearchFieldDataType.Double, filterable=True),
SearchField(name="description", type=SearchFieldDataType.String, filterable=True),
SearchField(name="vector", type=SearchFieldDataType.Collection(SearchFieldDataType.Single), searchable=True,
vector_search_dimensions=1536, vector_search_profile_name="myHnswProfile"),
]
vector_search = VectorSearch(
algorithms=[HnswAlgorithmConfiguration(name="myHnsw")],
profiles=[VectorSearchProfile(name="myHnswProfile", algorithm_configuration_name="myHnsw")]
)
semantic_config = SemanticConfiguration(
name="customer-semantic-config",
prioritized_fields=SemanticPrioritizedFields(title_field=SemanticField(field_name="Name"),
content_fields=[SemanticField(field_name="Region"),
SemanticField(field_name="Realm")])
)
semantic_search = SemanticSearch(configurations=[semantic_config])
customer_index = SearchIndex(name=customer_index_name, fields=fields, vector_search=vector_search,
semantic_search=semantic_search)
result = search_index_client.create_or_update_index(customer_index)
print(f'Customer Index {result.name} created')
return result
Note: While the creation of Azure OpenAI services, AI Search services, and indexes are critical foundational steps, diving into the detailed process would make this article too long. For the sake of brevity, I’ll focus on the core concepts and implementation steps that directly relate to the Retrieval-Augmented Generation (RAG) framework. Setting up these services is well-documented in Microsoft’s official resources, and I encourage you to explore those if you’re starting from scratch.
{
"id": "35c50d6f-279b-4d16-ae25-04d7ce60902d",
"fields": {
"OrderID": "ORD001",
"CustomerID": "CUST031",
"OfferID": "OFF068",
"OrderDate": "2024-01-14 15:36:31.160817",
"DeliveryDate": "2024-09-11",
"DeliveryFrom": "Khazad-d?m",
"DeliveryTo": "Moria",
"Quantity": 5,
"PricePerUnitUSD": 50000.0,
"TotalPriceUSD": 277000.0,
"Mine": "Grey Mountains Mine",
"vector": [0.00153, 0.01304, ..., -0.01797, -0.00536]
},
"description": "Order ORD001 placed by customer CUST031 was delivered from Khazad-d?m to Moria..."
}
# Loop through all the chunk files in the directory
for filename in os.listdir(chunk_directory):
if filename.endswith('.json'):
file_path = os.path.join(chunk_directory, filename)
with open(file_path, 'r', encoding='utf-8') as chunk_file:
chunk_data = json.load(chunk_file)
# Unpack the fields and vector for individual upload
document = chunk_data['fields'] # Unpack all key-value pairs from the 'fields'
document['vector'] = chunk_data['vector'] # Add the vector to the document
document['id'] = chunk_data['id']
document['description'] = chunk_data['description']
# Upload each document (normal upload)
try:
result = search_client.upload_documents(documents=[document])
print(f"Upload of {filename} succeeded: {result[0].succeeded}")
except Exception as e:
print(f"Failed to upload chunk {filename}: {e}")
query_embedding = get_embeddings_vector(user_query, openai_client, embedding_model)
# choose appropriate number of nearest neighbors
vector_query = VectorizedQuery(vector=query_embedding, k_nearest_neighbors=50,
fields="vector")
response = openai_client.chat.completions.create(
model='gpt-4o',
messages=[
{"role": "system", "content": "You are a helpful AI assistant for users, "
"who want to understand mithril and its pricing, orders, customers, "
"regions etc. Use the indexes and context given to you to "
"answer the questions."},
{"role": "user", "content": user_query},
{"role": "system",
"content": f"Here is some relevant information to help answer the query: {combined_context}"}
],
extra_body={ # Azure AI Search index is passed here
"data_sources": [
{
"type": "azure_search",
"parameters": {
"endpoint": search_crm_client._endpoint,
# This pulls from the SearchClient using env vars
"index_name": search_crm_index_name,
# Use the index from the environment variables
"authentication": {
"type": "api_key",
"key": azure_search_service_admin_key
}
}
}
]
}
)
Conclusion: A Self-Service Platform for Real-Time Insights
This platform transforms the way businesses, especially those handling large datasets, extract insights. Whether it’s steel pricing in manufacturing or analyzing financial trends in banking, this RAG-based solution reduces dependency on technical teams and accelerates decision-making.
In this article, we’ve walked through how Retrieval-Augmented Generation can be applied to structured data — driving powerful insights in real-time. The power of this solution lies in its versatility, and with the right architecture, it can scale across industries and use cases.
If you’re a data enthusiast or a business leader, think about how RAG can revolutionize your industry. This technology goes beyond dashboards and SQL — it allows for true self-service analytics. Try it out for yourself, or get in touch to learn more!