AI21Embeddings
This service is deprecated. :::
This will help you get started with AI21 embedding models using LangChain. For detailed documentation on AI21Embeddings
features and configuration options, please refer to the API reference.
Overviewโ
Integration detailsโ
Provider | Package |
---|---|
AI21 | langchain-ai21 |
Setupโ
To access AI21 embedding models you'll need to create an AI21 account, get an API key, and install the langchain-ai21
integration package.
Credentialsโ
Head to https://docs.ai21.com/ to sign up to AI21 and generate an API key. Once you've done this set the AI21_API_KEY
environment variable:
import getpass
import os
if not os.getenv("AI21_API_KEY"):
os.environ["AI21_API_KEY"] = getpass.getpass("Enter your AI21 API key: ")
To enable automated tracing of your model calls, set your LangSmith API key:
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
Installationโ
The LangChain AI21 integration lives in the langchain-ai21
package:
%pip install -qU langchain-ai21
Instantiationโ
Now we can instantiate our model object and generate chat completions:
from langchain_ai21 import AI21Embeddings
embeddings = AI21Embeddings(
# Can optionally increase or decrease the batch_size
# to improve latency.
# Use larger batch sizes with smaller documents, and
# smaller batch sizes with larger documents.
# batch_size=256,
)