Exploring the world of semantic search can be an exciting journey, especially when it involves powerful tools like Typesense. With its built-in embedding models, Typesense enables enhanced search capabilities that go beyond simple keyword matching. This guide will help you understand how to specify a model for auto-embedding generation when creating a collection, while also guiding potential contributors on how they can add new models to the supported list.
What Are Built-in Embedding Models?
Built-in embedding models are pre-trained machine learning models that Typesense supports for semantic and vector searches. These models understand the context and meaning behind words, allowing for more intelligent search results. If you have a model that you believe would enhance the functionality of Typesense, you can convert it to the ONNX format and create a Pull Request (PR) for its inclusion.
Using Typesense for Auto-Embedding Generation
Creating a collection in Typesense and specifying a model for embedding generation is straightforward. Here’s an illustrative example using a metaphor: imagine you’re setting up a library (the collection) and need to classify books (the data) in a way that makes sense (the embedding). Let’s see how this would look in practice:
curl -X POST \
http://localhost:8108/collections \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" \
-d '{
"name": "products",
"fields": [
{
"name": "product_name",
"type": "string"
},
{
"name": "embedding",
"type": "float[]",
"embed": {
"from": ["product_name"],
"model_config": {
"model_name": "tsall-MiniLM-L12-v2"
}
}
}
]
}'
Breaking Down the Code
Let’s break this down:
- curl -X POST: This command sends a request to create a new collection.
- http://localhost:8108/collections: This is the endpoint where the collection is created.
- X-TYPESENSE-API-KEY: Your secret key that authorizes the request.
- name: The name of your collection, in this case, “products”.
- fields: This part creates the structure of your data, where each field has a specified type.
- embedding: This specifies how to generate embeddings from the products, utilizing a model like “tsall-MiniLM-L12-v2”.
By visualizing the process like organizing a library, it helps understand how collections and embeddings work in tandem to promote effective searching.
How to Add Your Own Models
Do you have a model that could fit the Typesense ecosystem? Here’s how you can contribute:
Converting Models to ONNX Format
Before your model can be included, it needs to be converted to the ONNX format. Here’s how to do that for popular frameworks:
- Hugging Face Transformers: Follow the instructions available here using the optimum-cli.
- PyTorch: You can use the
torch.onnx
APIs to perform the conversion. More details can be found here. - TensorFlow: Use the
tf2onnx
tool for conversion, and refer to the guide here.
Creating a Model Configuration
Once your model is converted, ensure you organize the necessary files. Your model directory should include the following:
- Model File: The ONNX model file.
- Vocab File: The vocabulary file needed for the model.
- Model Config File: Named
config.json
, it should store keys like model type, checksums, and optional prefixes.
Troubleshooting
If you encounter challenges while using or contributing to Typesense embedding models, consider these troubleshooting steps:
- Ensure your API key is valid and that you are pointing to the correct server.
- Double-check the model configuration file for accuracy and completeness.
- Verify that the model has been successfully converted to the ONNX format.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
With the ability to integrate various embedding models, Typesense stands out as a powerful tool for semantic search. By learning how to effectively create collections and contribute your models, you can significantly enhance search experiences. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.