Enhancing Semantic Search with Trainable Embeddings: A Guide for Developers and Innovators

Introducing our new product: Trainable Embeddings — a low-overhead API that enables applications using Retrieval-Augmented Generation (RAG) with LLMs or semantic search to enhance accuracy and user experience. By using a trainable model that refines embeddings through feedback, our solution fosters smarter, personalized search results, designed specifically for developers and companies seeking to elevate their search capabilities.

Join our beta program for an exclusive early access to Trainable Embeddings! Simply email us at beta-embeddings@zopml.com with ‘Beta Access Request’ as your subject. We’re excited to collaborate with you!


Trainable Embeddings serves as an intermediate layer that customizes embeddings generated from foundation models. It learns and improves with feedback. By integrating this model into your application using a straightforward API, you can dynamically refine how search queries are understood and matched with content. Through the API, you can submit training data—comprising feedback on search outcomes—to continually enhance the model’s accuracy and relevance to your specific use case.

The process is designed to be intuitive for developers and accessible for companies at various scales. It begins with the collection of feedback on the efficacy of search results: identifying whether the most relevant document was retrieved and, if not, specifying the ideal result. This feedback is transformed into training examples, which then inform the model to adjust how it transforms embeddings, thereby optimizing future searches.

For those exploring or actively integrating LLMs and semantic search into their applications, the ability to fine-tune search results without extensive overhead is invaluable. Moreover, the model supports a generous threshold of free requests per month for hobbyists and early-stage projects, with scalable pricing for higher volumes of requests, ensuring that growing applications can maintain cost-effective access to advanced search capabilities.

The Importance of Semantic Search

Semantic search transcends traditional keyword matching by striving to understand the intent and contextual nuances behind queries. This is critical in applications where the depth, accuracy, and relevance of search results directly impact user satisfaction and engagement. Semantic search technologies, powered by LLMs, consider the broader context, synonyms, and the semantic relationships between words, providing a foundation for more intuitive and effective search experiences.

Our product, Trainable Embeddings, is designed to work in conjunction with off-the-shelf embedding providers such as OpenAI, Google, Facebook and Mistral. It uses these well-established embeddings as inputs, offering a customization layer that refines and adjusts them to meet the specific requirements of your application. You benefit from the foundational strengths of these leading technologies, but also gain the ability to tailor the search experience, enhancing accuracy and relevance to fit your unique use case more closely.

Applications and Opportunities

The potential applications of trainable embeddings and semantic search are vast and varied:

  • Content Discovery Platforms: Enhance user engagement by delivering precisely matched content recommendations based on the semantic understanding of user preferences and search queries.
  • Customer Support Bots: Improve the efficiency and satisfaction of automated support by accurately retrieving answers and resources in response to customer inquiries.
  • E-commerce Search: Drive sales and user satisfaction by connecting customers with the products they’re seeking through an enhanced understanding of search intent.
  • Research and Information Retrieval: Enable researchers and professionals to find relevant documents and data faster, with higher relevance to their specific inquiries.

Implementing Trainable Embeddings

For developers and technical teams, integrating trainable embeddings involves:

  1. API Integration: Create and API key and integrate the trainable embeddings API into your application, allowing for the submission of search queries and feedback.
  2. Feedback Loop Creation: Implement mechanisms within your app to collect and submit feedback on search results, turning user interactions into valuable training data.
  3. Continuous Learning and Adjustment: Utilize the evolving model to refine search functionalities.

See the appendix for examples in JavaScript and Python.


For software developers, startup founders, and companies leveraging or considering LLMs and semantic search, trainable embeddings present a significant opportunity to enhance search functionalities in a targeted, efficient manner. This technology not only promises improved search accuracy and user satisfaction but also offers a scalable solution adaptable to a wide range of applications and industries. As we move towards a more AI-integrated future, the ability to fine-tune and personalize search experiences becomes a pivotal competitive edge, empowering innovators to create applications that truly understand and respond to user needs.


Javascript Examples

Modifying an Embedding

async function modifyEmbedding(embedding, modelId) {
  const response = await fetch(
      method: 'POST',
      body: JSON.stringify({ 
      headers: { 
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${API_KEY}` 
  const data = await response.json();
  return data.modifiedEmbedding;

// Example embeddings and IDs
const embedding = [0.1, 0.2, 0.3, 0.4];
const modelId = 'your-model-id';

// Modifying an embedding
modifyEmbedding(embedding, modelId)
  .then(modified => console.log('Modified Embedding:', modified));

Training a Custom Model

async function trainCustomModel(documents, queries, modelId = '') {
  const response = await fetch('https://api.zopml.com/v1/models/train', {
    method: 'POST',
    body: JSON.stringify({ documents, queries, modelId }),
    headers: { 'Content-Type': 'application/json' },
  const data = await response.json(); // Assuming a successful response
  return data.modelId; // Return the new or refined model ID

// Example training data
const modelId = 'your-model-id';
const documents = { '123': [0.1, 0.2, 0.3, 0.4], ... };
const queries = [{ queryEmbedding: [0.15, 0.25, 0.35, 0.45], documentId: 123 }, ....];

// Training a custom model
trainCustomModel(documents, queries)
  .then(modelId => console.log('New Model ID:', modelId));

Python examples

Modifying an embedding

API_KEY = 'your_api_key'

def modify_embedding(embedding, model_id):
    url = 'https://api.zopml.com/v1/embeddings/modify'
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {API_KEY}'
    payload = {
        'embedding': embedding,
        'modelId': model_id
    response = requests.post(url, headers=headers, data=json.dumps(payload))
    if response.status_code == 200:
        data = response.json()
        return data['modifiedEmbedding']
        raise Exception(f"Error modifying embedding: {response.text}")

# Example of modifying embeddings
embedding = [0.1, 0.2, 0.3, 0.4]
model_id = 'your-model-id'
modified_embedding = modify_embedding(embedding, model_id)
print('Modified Embedding:', modified_embedding)

Training a Custom Model

def train_custom_model(documents, queries, model_id=''):
    url = 'https://api.zopml.com/v1/models/train'
    headers = {
        'Content-Type': 'application/json',
    payload = {
        'documents': documents,
        'queries': queries,
        'modelId': model_id
    response = requests.post(url, headers=headers, data=json.dumps(payload))
    if response.status_code == 200:
        data = response.json()
        return data['modelId']
        raise Exception(f"Error training model: {response.text}")

# Example training data
model_id = 'your-model-id'
documents = {'123': [0.1, 0.2, 0.3, 0.4]}  # Add more documents as needed
queries = [{'queryEmbedding': [0.15, 0.25, 0.35, 0.45], 'documentId': 123}]  # Add more queries as needed

# Training a custom model
new_model_id = train_custom_model(documents, queries, model_id)
print('New Model ID:', new_model_id)


Leave a Reply

Your email address will not be published. Required fields are marked *