PremAI Embeddings¶
PremAI is an unified platform that let's you build powerful production-ready GenAI powered applications with least effort, so that you can focus more on user experience and overall growth.
In this section we are going to dicuss how we can get access to different embedding model using PremEmbeddings
with llama-index
Installation and setup¶
We start by installing llama-index and premai-sdk. You can type the following command to install:
pip install premai llama-index
Before proceeding further, please make sure that you have made an account on Prem and already started a project. If not, then here's how you can start for free:
Sign in to PremAI, if you are coming for the first time and create your API key here.
Go to app.premai.io and this will take you to the project's dashboard.
Create a project and this will generate a project-id (written as ID). This ID will help you to interact with your deployed application.
Congratulations on creating your first deployed application on Prem 🎉 Now we can use langchain to interact with our application.
%pip install llama-index-llms-premai
from llama_index.embeddings.premai import PremAIEmbeddings
Setup PremAIEmbeddings instance in LlamaIndex¶
Once we imported our required modules, let's setup our client. For now let's assume that our project_id
is 8
. But make sure you use your project-id, otherwise it will throw error. In case of embeddings you also have to additionally pass model
. Here are the list of available models on PremAI.
Provider | Slug | Context Tokens |
---|---|---|
cohere | embed-english-v3.0 | N/A |
openai | text-embedding-3-small | 8191 |
openai | text-embedding-3-large | 8191 |
openai | text-embedding-ada-002 | 8191 |
replicate | replicate/all-mpnet-base-v2 | N/A |
together | togethercomputer/Llama-2-7B-32K-Instruct | N/A |
mistralai | mistral-embed | 4096 |
To change the model, you simply need to copy the slug
and access your embedding model.
import os
import getpass
if os.environ.get("PREMAI_API_KEY") is None:
os.environ["PREMAI_API_KEY"] = getpass.getpass("PremAI API Key:")
prem_embedding = PremAIEmbeddings(
project_id=8, model_name="text-embedding-3-large"
)
Calling the Embedding Model¶
Now you are all set. Now let's start using our embedding model with a single query followed by multiple queries (which is also called as a document)
query = "Hello, this is a test query"
query_result = prem_embedding.get_text_embedding(query)
print(f"Dimension of embeddings: {len(query_result)}")
Dimension of embeddings: 3072
query_result[:5]
[-0.02129288576543331, 0.0008162345038726926, -0.004556538071483374, 0.02918623760342598, -0.02547479420900345]