Perform Vector Search on a pipeline
📢 Note: The API is currently in Beta.
After creating a pipeline, you can perform a Vector Search on it.
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 = os.environ.get("VECTORIZE_ORGANIZATION_ID")
api_key = os.environ.get("VECTORIZE_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: {organization_id}")
const v = require('@vectorize-io/vectorize-client');
// Get credentials from environment variables
const organizationId = process.env.VECTORIZE_ORGANIZATION_ID;
const apiKey = process.env.VECTORIZE_API_KEY;
if (!organizationId || !apiKey) {
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: apiKey
});
const apiClient = new v.ApiClient(configuration);
console.log(`✅ API client initialized for organization: ${organizationId}`);
Call the retrieval endpoint
First, we need to retrieve the pipeline ID. If you created the pipeline via API, you should have the ID in the response. Otherwise you can always list the pipelines and get the ID from there. From the platform, you can navigate into the pipeline page and check the id in the browser url.
- Python
- Node.js
import vectorize_client as v
# Create pipelines API client
pipelines_api = v.PipelinesApi(apiClient)
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({
"your-org-id": "your-org-id",
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;
}
Complete Example
Here's all the code from this guide combined into a complete, runnable example:
- Python
- Node.js
import vectorize_client as v
import os
# Get credentials from environment variables
organization_id = os.environ.get("VECTORIZE_ORGANIZATION_ID")
api_key = os.environ.get("VECTORIZE_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: {organization_id}")
import vectorize_client as v
# Create pipelines API client
pipelines_api = v.PipelinesApi(apiClient)
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 v = require('@vectorize-io/vectorize-client');
// Get credentials from environment variables
const organizationId = process.env.VECTORIZE_ORGANIZATION_ID;
const apiKey = process.env.VECTORIZE_API_KEY;
if (!organizationId || !apiKey) {
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: apiKey
});
const apiClient = new v.ApiClient(configuration);
console.log(`✅ API client initialized for organization: ${organizationId}`);
const { PipelinesApi } = vectorize;
// Create pipelines API client
const pipelinesApi = new PipelinesApi(apiConfig);
try {
// Query the pipeline
const response = await pipelinesApi.retrieveDocuments({
"your-org-id": "your-org-id",
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;
}
Next Steps
- Learn how to work with metadata
- Explore deep research capabilities
- Understand pipeline monitoring and events