Embaas
embaas is a fully managed NLP API service that offers features like embedding generation, document text extraction, document to embeddings and more. You can choose avariety of pre-trained models.
In this tutorial, we will show you how to use the embaas Embeddings API to generate embeddings for a given text.
Prerequisites
Create your free embaas account athttps://embaas.io/register and generate anAPI key.
import os
# Set API key
embaas_api_key="YOUR_API_KEY"
# or set environment variable
os.environ["EMBAAS_API_KEY"]="YOUR_API_KEY"
from langchain_community.embeddingsimport EmbaasEmbeddings
API Reference:EmbaasEmbeddings
embeddings= EmbaasEmbeddings()
# Create embeddings for a single document
doc_text="This is a test document."
doc_text_embedding= embeddings.embed_query(doc_text)
# Print created embedding
print(doc_text_embedding)
# Create embeddings for multiple documents
doc_texts=["This is a test document.","This is another test document."]
doc_texts_embeddings= embeddings.embed_documents(doc_texts)
# Print created embeddings
for i, doc_text_embeddinginenumerate(doc_texts_embeddings):
print(f"Embedding for document{i+1}:{doc_text_embedding}")
# Using a different model and/or custom instruction
embeddings= EmbaasEmbeddings(
model="instructor-large",
instruction="Represent the Wikipedia document for retrieval",
)
For more detailed information about the embaas Embeddings API, please refer tothe official embaas API documentation.
Related
- Embedding modelconceptual guide
- Embedding modelhow-to guides