Skip to main content

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
Prerequisites
This guide assumes you've completed the Getting Started guide and have your API client initialized.

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:

  1. Stores your documents in a searchable format
  2. Retrieves relevant information when asked a question
  3. 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:

  1. Source Connector: Specifies where documents come from
  2. AI Platform: Processes and understands your documents (Vectorize's built-in AI)
  3. Destination: Stores processed documents for fast retrieval (Vectorize's vector store)
  4. 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:

  1. Your question is converted to a vector (mathematical representation)
  2. Vectorize finds the most relevant chunks from your documents
  3. These chunks are sent to the AI as context
  4. 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

  1. Upload more documents to see how the AI handles multiple sources
  2. Try different question types to understand the AI's capabilities
  3. Experiment with document formats like PDFs or Word docs

Level Up Your Skills

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!

Was this page helpful?