Embed
thanosql.embed()
The embed
function in ThanoSQL is designed to generate embeddings for given input data using a pre-trained model. This function utilizes various engines to provide efficient and high-quality embeddings for text, images, and other types of data.
Syntax
Parameters
Parameter | Type | Default | Description | Options |
---|---|---|---|---|
engine | string | 'huggingface' | The engine to use for generating embeddings. | 'huggingface' : Uses models from HuggingFace.'thanosql' : Uses ThanoSQL’s native models.'openai' : Uses models from OpenAI. |
input | string | The input data based on which the embeddings will be generated. It can be text, a URL, an S3 URI, or a path to a local file. | N/A | |
model | string | The name or path of the pre-trained text generation model. | Example: 'openai/clip-vit-base-patch32' | |
model_args | json | None | JSON string representing additional arguments for the model. | N/A |
tokenizer_args | json | None | JSON string representing additional arguments for the tokenizer. | N/A |
token | string | None | Token for authentication if required by the model. | N/A |
base_url | string | None | Base URL to point the client to a different endpoint than the default OpenAI API endpoint. This is only applicable when the engine is openai . | N/A |
Returns
- list: The generated embeddings based on the input.
Example Usage
The following examples are provided to help you become familiar with the ThanoSQL syntax. To try out these queries in real scenarios, please visit the Use Cases section for detailed tutorials and practical applications.
To run the models in this tutorial, you will need the following tokens:
- OpenAI Token: Required to access all the OpenAI-related tasks when using OpenAI as an engine. This token enables the use of OpenAI’s language models for various natural language processing tasks.
- Huggingface Token: Required only to access gated models such as Mistral on the Huggingface platform. Gated models are those that have restricted access due to licensing or usage policies, and a token is necessary to authenticate and use these models. For more information, check this Huggingface documentation. Make sure to have these tokens ready before proceeding with the tutorial to ensure a smooth and uninterrupted workflow.
Using Hugging Face Embedding Models (Text)
Here is an example of how to use the embed
function using a Hugging Face model:
On execution, we get:
Using Hugging Face Embedding Models (Image)
Here is an example of how to use the embed
function to generate embeddings for an image using Hugging Face model:
On execution, we get:
Using OpenAI Embedding Models
Here is an example of how to use the embed
function using an OpenAI model:
On execution, we get:
Using the OpenAI Client
Here is an example of how to use the embed
function with the base URL using the OpenAI Client:
On execution, we get:
Standalone Usage
Here is an example of how to use the embed
function as a standalone query:
On execution, we get:
Model Restrictions
When using the embed
function with the huggingface
engine, ensure that only models compatible with the HuggingFace AutoModel and AutoTokenizer are used. Verify that the selected model is supported by the HuggingFace library to avoid compatibility issues. Even with compatible models, some models might still not work. We are actively working on improving compatibility and functionality to provide a better user experience. For more information, refer to the official Hugging Face documentation.