| --- |
| title: 🧩 Embedding models |
| --- |
|
|
| ## Overview |
|
|
| Embedchain supports several embedding models from the following providers: |
|
|
| <CardGroup cols={4}> |
| <Card title="OpenAI" href="#openai"></Card> |
| <Card title="GoogleAI" href="#google-ai"></Card> |
| <Card title="Azure OpenAI" href="#azure-openai"></Card> |
| <Card title="AWS Bedrock" href="#aws-bedrock"></Card> |
| <Card title="GPT4All" href="#gpt4all"></Card> |
| <Card title="Hugging Face" href="#hugging-face"></Card> |
| <Card title="Vertex AI" href="#vertex-ai"></Card> |
| <Card title="NVIDIA AI" href="#nvidia-ai"></Card> |
| <Card title="Cohere" href="#cohere"></Card> |
| <Card title="Ollama" href="#ollama"></Card> |
| <Card title="Clarifai" href="#clarifai"></Card> |
| </CardGroup> |
|
|
| ## OpenAI |
|
|
| To use OpenAI embedding function, you have to set the `` ///account/ |
|
|
| Once |
|
|
| <CodeGroup> |
|
|
| ```python |
| import |
| from |
|
|
| os.environ['OPENAI_API_KEY'] = 'xxx' |
|
|
| # load |
| app |
|
|
| app.add("https://en.wikipedia.org/wiki/OpenAI") |
| app.query("What is OpenAI?") |
| ``` |
|
|
| ```yaml |
| embedder: |
| provider: openai |
| config: |
| model: 'text-embedding-3-small' |
| ``` |
|
|
| </CodeGroup> |
|
|
| * OpenAI announced two new embedding models: `text-embedding-3-small` and `text-embedding-3-large`. Embedchain supports both these models. Below you can find YAML config for both: |
|
|
| <CodeGroup> |
|
|
| ```yaml text-embedding-3-small.yaml |
| embedder: |
| provider: openai |
| config: |
| model: |
| ``` |
|
|
| ```yaml text-embedding-3-large.yaml |
| embedder: |
| provider: openai |
| config: |
| model: |
| ``` |
|
|
| </CodeGroup> |
|
|
| ## Google |
|
|
| To `` ///app/ |
|
|
| <CodeGroup> |
| ```python |
| import |
| from |
|
|
| os.environ["GOOGLE_API_KEY"] = "xxx" |
|
|
| app |
| ``` |
|
|
| ```yaml |
| embedder: |
| provider: google |
| config: |
| model: 'models/embedding-001' |
| task_type: "retrieval_document" |
| title: "Embeddings for Embedchain" |
| ``` |
| </CodeGroup> |
| <br/> |
| <Note> |
| For ///tutorials/ |
| </Note> |
|
|
| ## AWS Bedrock |
|
|
| To use AWS Bedrock embedding function, you have to set the AWS environment variable. |
|
|
| <CodeGroup> |
| ```python main.py |
| import os |
| from embedchain import App |
|
|
| os.environ[] = |
| os.environ[] = |
| os.environ[] = |
|
|
| app = App.from_config(config_path=) |
| ``` |
|
|
| ```yaml config.yaml |
| embedder: |
| provider: aws_bedrock |
| config: |
| model: |
| vector_dimension: 1024 |
| task_type: |
| title: |
| ``` |
| </CodeGroup> |
| <br/> |
| <Note> |
| For more details regarding the AWS Bedrock embedding model, please refer to the [AWS Bedrock documentation](https: |
| </Note> |
|
|
| ## Azure |
|
|
| To |
|
|
| <CodeGroup> |
|
|
| ```python |
| import |
| from |
|
|
| os.environ["OPENAI_API_TYPE"] = "azure" |
| os.environ["AZURE_OPENAI_ENDPOINT"] = "https://xxx.openai.azure.com/" |
| os.environ["AZURE_OPENAI_API_KEY"] = "xxx" |
| os.environ["OPENAI_API_VERSION"] = "xxx" |
|
|
| app |
| ``` |
|
|
| ```yaml |
| llm: |
| provider: azure_openai |
| config: |
| model: gpt-35-turbo |
| deployment_name: your_llm_deployment_name |
| temperature: 0.5 |
| max_tokens: 1000 |
| top_p: 1 |
| stream: false |
|
|
| embedder: |
| provider: azure_openai |
| config: |
| model: text-embedding-ada-002 |
| deployment_name: you_embedding_model_deployment_name |
| ``` |
| </CodeGroup> |
|
|
| You can find the list of models and deployment name on the [Azure OpenAI Platform](https: |
|
|
| ## GPT4ALL |
|
|
| GPT4All supports generating high quality embeddings of arbitrary length documents of text using a CPU optimized contrastively trained Sentence Transformer. |
|
|
| <CodeGroup> |
|
|
| ```python main.py |
| from embedchain import App |
|
|
| # load embedding model configuration from config.yaml file |
| app = App.from_config(config_path=) |
| ``` |
|
|
| ```yaml config.yaml |
| llm: |
| provider: gpt4all |
| config: |
| model: |
| temperature: 0.5 |
| max_tokens: 1000 |
| top_p: 1 |
| stream: false |
|
|
| embedder: |
| provider: gpt4all |
| ``` |
|
|
| </CodeGroup> |
|
|
| ## Hugging |
|
|
| Hugging |
|
|
| <CodeGroup> |
|
|
| ```python |
| from |
|
|
| # load |
| app |
| ``` |
|
|
| ```yaml |
| llm: |
| provider: huggingface |
| config: |
| model: 'google/flan-t5-xxl' |
| temperature: 0.5 |
| max_tokens: 1000 |
| top_p: 0.5 |
| stream: false |
|
|
| embedder: |
| provider: huggingface |
| config: |
| model: 'sentence-transformers/all-mpnet-base-v2' |
| model_kwargs: |
| trust_remote_code: True |
| ``` |
|
|
| </CodeGroup> |
|
|
| ## Vertex AI |
|
|
| Embedchain supports Google |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| chat-bison |
| |
| |
| |
| |
| |
| |
| textembedding-gecko |
| |
| |
| |
| |
| |
| |
| s AI models, such as Mixtral 8x7B, Llama 2 etc, through our API. These models are available in the [NVIDIA NGC catalog](https: |
|
|
|
|
| ### Usage |
|
|
| In order to use embedding models and LLMs from NVIDIA AI, create an account on [NVIDIA NGC Service](https: |
|
|
| Generate an API key from their dashboard. Set the API key as `NVIDIA_API_KEY` environment variable. Note that the `NVIDIA_API_KEY` will start with `nvapi-`. |
|
|
| Below is an example of how to use LLM model and embedding model from NVIDIA AI: |
|
|
| <CodeGroup> |
|
|
| ```python main.py |
| import os |
| from embedchain import App |
|
|
| os.environ[] = |
|
|
| config = { |
| : { |
| : { |
| : , |
| }, |
| }, |
| : { |
| : , |
| : { |
| : , |
| }, |
| }, |
| : { |
| : , |
| : { |
| : , |
| : 1024, |
| }, |
| }, |
| } |
|
|
| app = App.from_config(config=config) |
|
|
| app.add() |
| answer = app.query() |
| # Answer: The net worth of Elon Musk is subject to fluctuations based on the market value of his holdings in various companies. |
| # As of March 1, 2024, his net worth is estimated to be approximately $210 billion. However, this figure can change rapidly due to stock market fluctuations and other factors. |
| # Additionally, his net worth may include other assets such as real estate and art, which are not reflected in his stock portfolio. |
| ``` |
| </CodeGroup> |
|
|
|
|
| ## Cohere |
|
|
| To ///welcome/ |
|
|
| Generate `` |
|
|
| Once |
|
|
| <CodeGroup> |
|
|
| ```python |
| import |
| from |
|
|
| os.environ['COHERE_API_KEY'] = 'xxx' |
|
|
| # load |
| app |
| ``` |
|
|
| ```yaml |
| embedder: |
| provider: cohere |
| config: |
| model: 'embed-english-light-v3.0' |
| ``` |
|
|
| </CodeGroup> |
|
|
| * Cohere has few embedding models: `embed-english-v3.0`, `embed-multilingual-v3.0`, `embed-multilingual-light-v3.0`, `embed-english-v2.0`, `embed-english-light-v2.0` and `embed-multilingual-v2.0`. Embedchain supports all these models. Below you can find YAML config for all: |
|
|
| <CodeGroup> |
|
|
| ```yaml embed-english-v3.0.yaml |
| embedder: |
| provider: cohere |
| config: |
| model: |
| vector_dimension: 1024 |
| ``` |
|
|
| ```yaml embed-multilingual-v3.0.yaml |
| embedder: |
| provider: cohere |
| config: |
| model: |
| vector_dimension: 1024 |
| ``` |
|
|
| ```yaml embed-multilingual-light-v3.0.yaml |
| embedder: |
| provider: cohere |
| config: |
| model: |
| vector_dimension: 384 |
| ``` |
|
|
| ```yaml embed-english-v2.0.yaml |
| embedder: |
| provider: cohere |
| config: |
| model: |
| vector_dimension: 4096 |
| ``` |
|
|
| ```yaml embed-english-light-v2.0.yaml |
| embedder: |
| provider: cohere |
| config: |
| model: |
| vector_dimension: 1024 |
| ``` |
|
|
| ```yaml embed-multilingual-v2.0.yaml |
| embedder: |
| provider: cohere |
| config: |
| model: |
| vector_dimension: 768 |
| ``` |
|
|
| </CodeGroup> |
|
|
| ## Ollama |
|
|
| Ollama ///download) and keep it running before using the embedding model. |
|
|
| You can find the list of models at [Ollama Embedding Models](https: |
|
|
| Below is an example of how to use embedding model Ollama: |
|
|
| <CodeGroup> |
|
|
| ```python main.py |
| import os |
| from embedchain import App |
|
|
| # load embedding model configuration from config.yaml file |
| app = App.from_config(config_path=) |
| ``` |
|
|
| ```yaml config.yaml |
| embedder: |
| provider: ollama |
| config: |
| model: |
| ``` |
|
|
| </ |
|
|
| ## Clarifai |
|
|
| Install |
|
|
| ```bash |
| pip |
| ``` |
|
|
| set `` ///settings//Embedder class. |
|
|
| Now you are all set with exploring Embedchain. |
|
|
| <CodeGroup> |
|
|
| ```python main.py |
| import os |
| from embedchain import App |
|
|
| os.environ[] = |
|
|
| # load llm and embedder configuration from config.yaml file |
| app = App.from_config(config_path=) |
|
|
| #Now let |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |