Embedding Models API
EmbeddingModel
Bases: SynalinksSaveable
An embedding model API wrapper.
Embedding models are a type of machine learning model used to convert high-dimensional data, such as text into lower-dimensional vector representations while preserving the semantic meaning and relationships within the data. These vector representations, known as embeddings, allow for more efficient and effective processing in various tasks.
Many providers are available like OpenAI, Azure OpenAI, Vertex AI or Ollama.
For the complete list of models, please refer to the providers documentation.
Using OpenAI models
import synalinks
import os
os.environ["OPENAI_API_KEY"] = "your-api-key"
embedding_model = synalinks.EmbeddingModel(
model="openai/text-embedding-ada-002",
)
Using Azure OpenAI models
import synalinks
import os
os.environ["AZURE_API_KEY"] = "your-api-key"
os.environ["AZURE_API_BASE"] = "your-api-base"
os.environ["AZURE_API_VERSION"] = "your-api-version"
embedding_model = synalinks.EmbeddingModel(
model="azure/<your_deployment_name>",
)
Using VertexAI models
import synalinks
import os
embedding_model = synalinks.EmbeddingModel(
model="vertex_ai/text-embedding-004",
vertex_project = "hardy-device-38811", # Your Project ID
vertex_location = "us-central1", # Project location
)
Using Ollama models
Note: Obviously, use an .env
file and .gitignore
to avoid
putting your API keys in the code or a config file that can lead to
leackage when pushing it into repositories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
The model to use. |
None
|
api_base
|
str
|
Optional. The endpoint to use. |
None
|
retry
|
int
|
Optional. The number of retry. |
5
|
fallback
|
EmbeddingModel
|
Optional. The embedding model to fallback if anything is wrong. |
None
|
Source code in synalinks/src/embedding_models/embedding_model.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
__call__(texts, **kwargs)
async
Call method to get dense embeddings vectors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
list
|
A list of texts to embed. |
required |
Returns:
Type | Description |
---|---|
list
|
The list of corresponding vectors. |