Skip to main content
In this tutorial, you’ll learn how to integrate Voyage AI with Modelence to build powerful semantic search capabilities. You’ll learn how to:
  • Generate embeddings using Voyage AI’s embedding models
  • Store embeddings in MongoDB using vector fields
  • Perform vector search with MongoDB’s vector search capabilities
  • Use reranking to improve search results
This tutorial assumes you’ve already created a Modelence project and completed the setup. If you haven’t done so, please complete those steps first.

What is Voyage AI?

Voyage AI provides state-of-the-art embedding and reranking models that enable semantic search, recommendation systems, and RAG (Retrieval-Augmented Generation) applications. Their models are optimized for:
  • High-quality embeddings for semantic similarity
  • Reranking to improve search result relevance
  • Domain-specific fine-tuning options

Prerequisites

Before starting, you’ll need:
  1. A Voyage AI API key - Get one here
  2. A Modelence account with MongoDB configured

Quick Start with Template

The fastest way to get started is using the Voyage AI template:
This creates a ready-to-use project with all the code from this tutorial pre-configured.

Setup Steps

  1. Create an account on cloud.modelence.com
  2. Create an application and local environment in the Modelence Cloud dashboard
  3. Open the Settings page of your environment and click on Setup Local Environment
  4. Copy the command from the “Connect to Modelence Cloud” section and execute it in your project directory
  5. Add your Voyage AI API key:
    • Get your API key from voyageai.com
    • In the Modelence Cloud dashboard, open your environment’s Application tab and set the voyage.apiKey config to your API key
  6. Run the project:
You can also view a live demo of the complete example.

Manual Setup

If you want to add Voyage AI to an existing project, follow these steps:

Step 1: Install Dependencies

Install the Voyage AI client library:

Step 2: Create a Document Store with Vector Embeddings

Stores in Modelence support vector embeddings out of the box with the schema.embedding() type and vector search indexes. Create a new directory src/server/voyage and add a db.ts file:
src/server/voyage/db.ts
The schema.embedding() type is a special type for storing vector embeddings. The vectorIndex() method creates a MongoDB vector search index for fast similarity searches.

Step 3: Create Voyage AI Helper Functions

Create a voyage.ts file to handle embedding generation and reranking:
src/server/voyage/voyage.ts

Key Points:

  • Input Type: Voyage AI supports different input types (query vs document) to optimize embeddings for different use cases
  • Model Selection: voyage-3.5 is the latest embedding model supporting 4 dimension options (256, 512, 1024 default, and 2048). See all available embedding models
  • Reranking: Improves search results by reordering them based on relevance to the query. See all available reranker models

Step 4: Create a Module with Search Capabilities

Create an index.ts file to tie everything together:
src/server/voyage/index.ts
The vectorSearch() method performs semantic search using MongoDB’s vector search capabilities:
  • field: The field containing the embedding vectors
  • embedding: The query embedding to search for
  • numCandidates: Number of candidates to consider (higher = more accurate but slower)
  • limit: Maximum number of results to return
  • projection: Fields to include in results

Step 5: Include the Module

Add the Voyage module to your main server file:
src/server/app.ts

Step 6: Configure the API Key

You can configure the Voyage AI API key in two ways:

Option 1: Environment Variable

Add to your .env file:

Option 2: Module Config

Store it securely in MongoDB using Modelence’s config system:

Step 7: Build the Frontend

Create a React component to interact with your semantic search backend:
src/client/pages/VoyageSearchPage.tsx

How It Works

  1. Document Ingestion: When you add a document, the content is sent to Voyage AI to generate an embedding vector
  2. Storage: The embedding is stored alongside the document in MongoDB
  3. Search: When searching, your query is converted to an embedding and MongoDB finds similar vectors
  4. Reranking: Results are reranked using Voyage AI’s reranking model for improved relevance

Use Cases

This pattern is perfect for:
  • Knowledge bases with semantic search
  • Support chatbots with contextual document retrieval
  • Recommendation systems based on content similarity
  • RAG applications for AI assistants

Complete Example

Want to see the full working code? Check out the complete example:

Complete Voyage AI Example

See the complete source code with a polished UI and additional features.

Next Steps