Build Your First RAG App with Vectorize
In this guide, you'll build a working Retrieval-Augmented Generation (RAG) pipeline using the Vectorize API. You'll upload documents, create a retrieval pipeline, and run your first structured query — all using live, production-ready code examples.
What You'll Build
By the end of this guide, you'll have:
- A working RAG pipeline that processes your documents
- A retrieval endpoint that can answer questions about your uploaded content
- Familiarity with core Vectorize concepts
Prerequisites
Before you begin, you'll need:
- A Vectorize account
- An API access token (how to create one)
- Your organization ID (see below)
Finding your Organization ID
Your organization ID is in the Vectorize platform URL:
https://platform.vectorize.io/organization/[YOUR-ORG-ID]
For example, if your URL is:
https://platform.vectorize.io/organization/ecf3fa1d-30d0-4df1-8af6-f4852bc851cb
Your organization ID is: ecf3fa1d-30d0-4df1-8af6-f4852bc851cb
API Client Setup
- Python
- Node.js
import vectorize_client as v
import os
# Get credentials from environment variables
organization_id = "your-org-id"
api_key = "your-api-key"
if not organization_id or not api_key:
raise ValueError("Please set VECTORIZE_ORGANIZATION_ID and VECTORIZE_API_KEY environment variables")
# Initialize the API client
configuration = v.Configuration(
host="https://api.vectorize.io",
api_key={"ApiKeyAuth": api_key}
)
api = v.ApiClient(configuration)
print(f"✅ API client initialized for organization: {"your-org-id"}")
const v = require('@vectorize-io/vectorize-client');
// Get credentials from environment variables
const organizationId = "your-env-value";
const "your-api-key" = "your-env-value";
if (!organizationId || !"your-api-key") {
throw new Error("Please set VECTORIZE_ORGANIZATION_ID and VECTORIZE_API_KEY environment variables");
}
// Initialize the API client
const configuration = new v.Configuration({
basePath: 'https://api.vectorize.io',
accessToken: "your-api-key"
});
const apiClient = new v.ApiClient(configuration);
console.log(`✅ API client initialized for organization: ${organizationId}`);
What is RAG?
Retrieval-Augmented Generation (RAG) combines 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 answers using your specific content
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:
- Python
- Node.js
# 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
const { SourceConnectorsApi } = vectorize;
// Create the connectors API client
const connectorsApi = new SourceConnectorsApi(apiConfig);
let connectorId;
try {
// Create a file upload connector
const fileUpload = {
name: 'my-document-upload',
type: 'FILE_UPLOAD',
config: {}
};
const response = await connectorsApi.createSourceConnector({
organizationId: organizationId,
createSourceConnectorRequest: fileUpload
});
connectorId = response.connector.id;
console.log(`✅ Created file upload connector: ${connectorId}`);
} catch (error) {
console.log(`❌ Error creating connector: ${error.message}`);
throw error;
}
Step 2: Upload Your First Document
Now let's upload a document. In this example, we’re uploading a simple .txt file for clarity. You can upload PDFs, Word docs, or any supported text format — the upload process is the same regardless of file type.
- Python
- Node.js
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
const { UploadsApi } = vectorize;
// Create uploads API client
const uploadsApi = new UploadsApi(apiConfig);
try {
// Step 1: Get upload URL
const uploadRequest = {
name: fileName,
contentType: 'text/plain'
};
const startResponse = await uploadsApi.startFileUploadToConnector({
organizationId: organizationId,
connectorId: sourceConnectorId,
startFileUploadToConnectorRequest: uploadRequest
});
// Step 2: Upload file to the URL
const fileBuffer = fs.readFileSync(filePath);
const fileStats = fs.statSync(filePath);
const response = await fetch(startResponse.uploadUrl, {
method: 'PUT',
body: fileBuffer,
headers: {
'Content-Type': 'text/plain',
'Content-Length': fileStats.size.toString()
}
});
if (response.status === 200) {
console.log(`✅ Successfully uploaded: ${fileName}`);
} else {
console.log(`❌ Upload failed: ${response.status}`);
}
} catch (error) {
console.log(`❌ Error uploading file: ${error.message}`);
throw error;
}
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:
- Python
- Node.js
# 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
const { PipelinesApi } = vectorize;
// Create pipelines API client
const pipelinesApi = new PipelinesApi(apiConfig);
let pipelineId;
try {
// Configure your pipeline
const pipelineConfig = {
pipelineName: 'My First RAG Pipeline',
sourceConnectors: [
{
id: sourceConnectorId,
type: 'FILE_UPLOAD',
config: {}
}
],
aiPlatformConnector: {
id: aiPlatformConnectorId, // Uses Vectorize's built-in AI
type: 'VECTORIZE',
config: {}
},
destinationConnector: {
id: destinationConnectorId, // Uses Vectorize's built-in vector store
type: 'VECTORIZE',
config: {}
},
schedule: { type: 'manual' }
};
// Create the pipeline
const response = await pipelinesApi.createPipeline({
organizationId: organizationId,
pipelineConfigurationSchema: pipelineConfig
});
pipelineId = response.data.id;
console.log(`✅ Created pipeline: ${pipelineId}`);
} catch (error) {
console.log(`❌ Error creating pipeline: ${error.message}`);
throw error;
}
What's Happening Here?
When you create a pipeline:
- Source Connector: Specifies where documents come from
- AI Platform Connector: Processes and understands your documents (Vectorize's built-in AI)
- Destination Connector: 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:
- Python
- Node.js
# 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
const { PipelinesApi } = vectorize;
// Create pipelines API client
const pipelinesApi = new PipelinesApi(apiConfig);
console.log('Waiting for pipeline to process your document...');
const maxWaitTime = 300000; // 5 minutes in milliseconds
const startTime = Date.now();
while (true) {
try {
// Check pipeline status
const pipeline = await pipelinesApi.getPipeline({
organizationId: organizationId,
pipelineId: pipelineId
});
const status = pipeline.data.status;
// Check if ready
if (status === 'LISTENING') {
console.log('✅ Pipeline is ready!');
break;
} else if (status === 'PROCESSING') {
console.log('⚙️ Still processing...');
} else if (['ERROR_DEPLOYING', 'SHUTDOWN'].includes(status)) {
console.log(`❌ Pipeline error: ${status}`);
break;
}
// Check timeout
if (Date.now() - startTime > maxWaitTime) {
console.log('⏰ Timeout waiting for pipeline');
break;
}
await new Promise(resolve => setTimeout(resolve, 10000)); // Check every 10 seconds
} catch (error) {
console.log(`❌ Error checking status: ${error.message}`);
break;
}
}
Pipeline States
- DEPLOYING: Pipeline is being set up
- PROCESSING: Actively processing documents
- LISTENING: Ready and waiting for queries
For a complete list of pipeline states, see Understanding Pipeline Status.
Step 5: Query Your RAG Pipeline
Once the pipeline is ready, you can query it:
- Python
- Node.js
# Create pipelines API client
pipelines_api = v.PipelinesApi(api)
try:
# Query the pipeline
response = pipelines_api.retrieve_documents(
organization_id,
pipeline_id,
v.RetrieveDocumentsRequest(
question="How to call the API?",
num_results=5
)
)
# Display results
print(f"Found {len(response.documents)} relevant documents:\n")
for i, doc in enumerate(response.documents, 1):
print(f"Result {i}:")
print(f" Content: {doc.text[:200]}...") # Use 'text' instead of 'content'
print(f" Relevance Score: {doc.relevancy}") # Use 'relevancy' instead of 'score'
print(f" Document ID: {doc.id}")
print()
except Exception as e:
print(f"❌ Error querying pipeline: {e}")
raise
const { PipelinesApi } = vectorize;
// Create pipelines API client
const pipelinesApi = new PipelinesApi(apiConfig);
try {
// Query the pipeline
const response = await pipelinesApi.retrieveDocuments({
organizationId: organizationId,
pipelineId: pipelineId,
retrieveDocumentsRequest: {
question: 'How to call the API?',
numResults: 5
}
});
// Display results
console.log(`Found ${response.documents.length} relevant documents:\n`);
response.documents.forEach((doc, index) => {
console.log(`Result ${index + 1}:`);
console.log(` Content: ${doc.text.substring(0, 200)}...`); // Use 'text' instead of 'content'
console.log(` Relevance Score: ${doc.relevancy}`); // Use 'relevancy' instead of 'score'
console.log(` Document ID: ${doc.id}`);
console.log();
});
} catch (error) {
console.log(`❌ Error querying pipeline: ${error.message}`);
throw error;
}
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
For quick testing, Vectorize provides an interactive chatbot for each pipeline. You can access it at:
https://platform.vectorize.io/pipelines/[your-pipeline-id]/chat
This uses the same retrieval endpoint you've just configured. It’s useful 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 with Vectorize.
Here are some next steps to explore:
- Make Your AI Smarter with Metadata: Add filtering and context to your searches.
- Understanding RAG Pipelines: Deep dive into how pipelines work.
When you're ready to add structured metadata and filtering to your pipeline, try defining a schema using the Visual Schema Editor or API.