Trainable Embeddings

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. Early adopters get free API credits and exclusive early access to Trainable Embeddings! Simply email us at beta-embeddings@zoplabs.com with ‘Beta Access Request’ as your subject. We’re excited to collaborate with you!

Overview

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.

Conclusion

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.

Appendix

JavaScript Examples

Modifying a batch of Embeddings

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

}

// Example of modifying a batch of embeddings
const embedding = [[0.1, 0.2, 0.3, 0.4], ...];
const modelId = 'your-model-id';

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

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',
        'Authorization': `Bearer ${API_KEY}`
        },
  });
  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 a batch of embeddings

API_KEY = 'your_api_key'

def modify_embedding(embeddings, model_id):
    url = 'https://api.zopml.com/v1/embeddings/modify'
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {API_KEY}'
    }
    payload = {
        'embeddings': embeddings,
        'modelId': model_id
    }
    response = requests.post(
        url, 
        headers=headers,
        data=json.dumps(payload))

    if response.status_code == 200:
        data = response.json()
        return data['modifiedEmbedding']
    else:
        raise Exception(f"Error modifying embedding: {response.text}")
        
# Example of modifying a batch of embeddings
embeddings = [[0.1, 0.2, 0.3, 0.4], ...]
model_id = 'your-model-id'
modified_embeddings = modify_embedding(embeddings, model_id)
print('Modified Embedding:', modified_embeddings)

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',
        'Authorization': f'Bearer {API_KEY}'
    }
    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']
    else:
        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)

Posted

in

by

Tags: