Conecte documentos con incrustaciones (embeddings) para crear un asistente de búsqueda inteligente.
Learn how to build a Retrieval-Augmented Generation (RAG) assistant that answers questions using your own documents. In this guide, you'll index content with embeddings, perform semantic search, and generate accurate, context-aware responses.
Overview
A RAG (Retrieval-Augmented Generation) application combines a language model with a knowledge base. Instead of relying only on the model's training data, relevant documents are retrieved first and then provided as context for generating an answer.
This approach improves accuracy and enables AI applications to answer questions using your own data.
Estimated time: 20–30 minutes
Prerequisites
Before starting, ensure you have:
A NovaAI project
API authentication configured
Documents to index
Access to the Embeddings and Vector Store APIs
Tip: RAG works best with clean, well-structured documents rather than large unprocessed files.
Tip: RAG works best with clean, well-structured documents rather than large unprocessed files.
RAG Architecture
Rendering diagram…
1
Upload Your Documents
Start by uploading the documents you want your assistant to search.
1
Upload Your Documents
Start by uploading the documents you want your assistant to search.
Supported examples include:
Product documentation
Knowledge bases
User manuals
Internal company documents
FAQs
2
Generate Embeddings
Convert your documents into vector embeddings.
1constembedding=awaitclient.embeddings.create({
2model:"nova-embed-1",
3input:documentText
4});
Each document is transformed into a numerical representation that enables semantic search.
2
Generate Embeddings
Convert your documents into vector embeddings.
1constembedding=awaitclient.embeddings.create({
2model:"nova-embed-1",
3input:documentText
4});
Each document is transformed into a numerical representation that enables semantic search.
3
Store the Embeddings
Save the generated vectors in your Vector Store.
KnowledgeBase
├── ProductDocs
├── APIReference
├── FAQs
├── Tutorials
└── ReleaseNotes
Organizing documents into logical collections makes retrieval more efficient.
3
Store the Embeddings
Save the generated vectors in your Vector Store.
KnowledgeBase
├── ProductDocs
├── APIReference
├── FAQs
├── Tutorials
└── ReleaseNotes
Organizing documents into logical collections makes retrieval more efficient.
4
Search for Relevant Content
When a user asks a question, convert the query into an embedding and search for the most relevant documents.
1constresults=awaitclient.vectorStore.search({
2query:userQuestion,
3top_k:5
4});
The search returns the documents most closely related to the user's question.
4
Search for Relevant Content
When a user asks a question, convert the query into an embedding and search for the most relevant documents.
1constresults=awaitclient.vectorStore.search({
2query:userQuestion,
3top_k:5
4});
The search returns the documents most closely related to the user's question.
5
Generate the Answer
Pass the retrieved documents to the chat model as context.
1constresponse=awaitclient.chat.create({
2model:"nova-chat-4",
3messages:[
4{
5role:"system",
6content:"Answer only using the provided documentation."
7},
8{
9role:"user",
10content:userQuestion
11}
12]
13});
The model combines the retrieved information with the user's question to generate a relevant response.
5
Generate the Answer
Pass the retrieved documents to the chat model as context.
1constresponse=awaitclient.chat.create({
2model:"nova-chat-4",
3messages:[
4{
5role:"system",
6content:"Answer only using the provided documentation."
7},
8{
9role:"user",
10content:userQuestion
11}
12]
13});
The model combines the retrieved information with the user's question to generate a relevant response.
Best Practices
Recommendation
Benefit
Split large documents into smaller chunks
Improves retrieval accuracy.
Update embeddings when content changes
Keeps results current.
Retrieve only the most relevant documents
Reduces token usage.
Include source references
Makes answers easier to verify.
Note: RAG does not retrain the model. Instead, it provides relevant information at request time, allowing responses to stay up to date without fine-tuning.
Note: RAG does not retrain the model. Instead, it provides relevant information at request time, allowing responses to stay up to date without fine-tuning.
Completed
Congratulations!
You've built a Retrieval-Augmented Generation assistant capable of answering questions using your own knowledge base.