Build Your First RAG App with Vectorize
Welcome to your first step in building AI-powered applications with Vectorize! In this guide, you'll create a complete Retrieval-Augmented Generation (RAG) application from scratch. In just 15 minutes, you'll have a working AI that can answer questions about your documents.
What You'll Build
By the end of this guide, you'll have:
- A working RAG pipeline that processes your documents
- An AI that can answer questions about your uploaded content
- Understanding of the core Vectorize concepts
- Foundation for building more advanced AI applications
What is RAG?
Retrieval-Augmented Generation (RAG) combines the power of large language models with your own data. Instead of relying on an AI's general knowledge, RAG:
- Stores your documents in a searchable format
- Retrieves relevant information when asked a question
- Generates accurate answers using your specific content
Think of it as giving an AI assistant perfect memory of your documents.
Step 1: Create a File Upload Connector
A connector is how you get data into Vectorize. For this guide, we'll use a File Upload connector to upload documents directly:
# Create the connectors API client
connectors_api = v.SourceConnectorsApi(api)
try:
# Create a file upload connector
file_upload = v.FileUpload(
name="my-document-upload",
type="FILE_UPLOAD",
config={}
)
request = v.CreateSourceConnectorRequest(file_upload)
response = connectors_api.create_source_connector(
organization_id,
request
)
connector_id = response.connector.id
print(f"✅ Created file upload connector: {connector_id}")
except Exception as e:
print(f"❌ Error creating connector: {e}")
raise
Step 2: Upload Your First Document
Now let's upload a document. For this example, we'll create a simple text file about RAG, but you can upload PDFs, Word docs, or any text file:
import urllib3
# Create uploads API client
uploads_api = v.UploadsApi(api)
try:
# Step 1: Get upload URL
upload_request = v.StartFileUploadToConnectorRequest(
name=file_name,
content_type="text/plain"
)
start_response = uploads_api.start_file_upload_to_connector(
organization_id,
source_connector_id,
start_file_upload_to_connector_request=upload_request
)
# Step 2: Upload file to the URL
http = urllib3.PoolManager()
with open(file_path, "rb") as f:
response = http.request(
"PUT",
start_response.upload_url,
body=f,
headers={
"Content-Type": "text/plain",
"Content-Length": str(os.path.getsize(file_path))
}
)
if response.status == 200:
print(f"✅ Successfully uploaded: {file_name}")
else:
print(f"❌ Upload failed: {response.status}")
except Exception as e:
print(f"❌ Error uploading file: {e}")
raise
Supported File Types
Vectorize can process:
- 📄 PDFs
- 📝 Text files (.txt, .md)
- 📊 Microsoft Office documents (.docx, .xlsx, .pptx)
- 🖼️ Images with text (OCR)
- 🌐 HTML files
- 📧 Emails (.eml)
Step 3: Create Your RAG Pipeline
A pipeline connects your data source (the File Upload connector) to AI processing and storage. Vectorize provides built-in AI and vector storage to get you started quickly:
# Create pipelines API client
pipelines_api = v.PipelinesApi(api)
try:
# Configure your pipeline
pipeline_config = v.PipelineConfigurationSchema(
pipeline_name="My First RAG Pipeline",
source_connectors=[
v.PipelineSourceConnectorSchema(
id=source_connector_id,
type="FILE_UPLOAD",
config={}
)
],
ai_platform_connector=v.PipelineAIPlatformConnectorSchema(
id=ai_platform_connector_id, # Uses Vectorize's built-in AI
type="VECTORIZE",
config={}
),
destination_connector=v.PipelineDestinationConnectorSchema(
id=destination_connector_id, # Uses Vectorize's built-in vector store
type="VECTORIZE",
config={}
),
schedule=v.ScheduleSchema(type="manual")
)
# Create the pipeline
response = pipelines_api.create_pipeline(
organization_id,
pipeline_config
)
pipeline_id = response.data.id
print(f"✅ Created pipeline: {pipeline_id}")
except Exception as e:
print(f"❌ Error creating pipeline: {e}")
raise
What's Happening Here?
When you create a pipeline:
- Source Connector: Specifies where documents come from
- AI Platform: Processes and understands your documents (Vectorize's built-in AI)
- Destination: Stores processed documents for fast retrieval (Vectorize's vector store)
- Schedule: When to check for new documents (manual = on-demand)
Step 4: Wait for Processing
Your pipeline needs a few moments to process the uploaded document. Let's monitor its progress:
# Create pipelines API client
pipelines_api = v.PipelinesApi(api)
print("Waiting for pipeline to process your document...")
max_wait_time = 300 # 5 minutes
start_time = time.time()
while True:
try:
# Check pipeline status
pipeline = pipelines_api.get_pipeline(organization_id, pipeline_id)
status = pipeline.data.status
# Check if ready
if status == "LISTENING":
print("✅ Pipeline is ready!")
break
elif status == "PROCESSING":
print("⚙️ Still processing...")
elif status in ["ERROR_DEPLOYING", "SHUTDOWN"]:
print(f"❌ Pipeline error: {status}")
break
# Check timeout
if time.time() - start_time > max_wait_time:
print("⏰ Timeout waiting for pipeline")
break
time.sleep(10) # Check every 10 seconds
except Exception as e:
print(f"❌ Error checking status: {e}")
break
Pipeline States
- DEPLOYING: Pipeline is being set up
- PROCESSING: Actively processing documents
- LISTENING: Ready and waiting for queries
- IDLE: No current activity
- ERROR: Something went wrong (check logs)
Step 5: Query Your RAG Pipeline
Now for the exciting part - asking questions about your document! Once the pipeline is ready, you can query it:
# TODO: Add query/search functionality once API endpoint is confirmed
# This will typically look like:
#
# search_api = v.SearchApi(api)
#
# query = "What are the benefits of RAG?"
# response = search_api.search_pipeline(
# organization_id,
# pipeline_id,
# query=query,
# top_k=5
# )
#
# print("Search Results:")
# for result in response.results:
# print(f"- {result.text}")
# print(f" Score: {result.score}")
print("🔍 Query functionality coming soon!")
print(" Once implemented, you'll be able to search your documents")
print(" and get AI-powered answers based on your content.")
How Queries Work
When you submit a query:
- Your question is converted to a vector (mathematical representation)
- Vectorize finds the most relevant chunks from your documents
- These chunks are sent to the AI as context
- The AI generates an answer based on your specific content
Understanding Your Results
The query response includes:
- Answer: The AI-generated response to your question
- Sources: Which document chunks were used
- Confidence: How relevant the retrieved content was
- Metadata: Additional information about the sources
Try the Interactive Chatbot
Vectorize automatically creates a chatbot interface for every pipeline. You can access it at:
https://app.vectorize.io/pipelines/[your-pipeline-id]/chat
This is great for:
- Testing your pipeline quickly
- Sharing with non-technical users
- Demonstrating your RAG application
What's Next?
Congratulations! You've built your first RAG application. Here's what you can explore next:
Immediate Next Steps
- Upload more documents to see how the AI handles multiple sources
- Try different question types to understand the AI's capabilities
- Experiment with document formats like PDFs or Word docs
Level Up Your Skills
- Level 2: Make Your AI Smarter with Metadata - Add filtering and context to your searches
- Understanding RAG Pipelines - Deep dive into how pipelines work
- Connect External Data Sources - Automate document ingestion
Complete Working Example
For a complete working example that ties all these steps together, check out our RAG quickstart repository.
Troubleshooting
Pipeline stuck in DEPLOYING?
- Check your connector configuration
- Ensure your organization has available resources
- Look for error messages in the pipeline details
No results from queries?
- Verify your document was uploaded successfully
- Check that the pipeline status is "LISTENING"
- Try broader questions first
Authentication errors?
- Double-check your API key and organization ID
- Ensure environment variables are set correctly
- Verify your API key has the necessary permissions
🎉 Congratulations! You've built your first RAG application with Vectorize. You're now ready to build more sophisticated AI applications. Continue to Make Your AI Smarter With Metadata to learn about metadata and filtering!