The TogetherEmbedder can be used to embed text data into vectors using the Together API. Together uses the OpenAI API specification, so the TogetherEmbedder class is similar to the OpenAIEmbedder class, incorporating adjustments to ensure compatibility with the Together platform. Get your key from here.

Usage

cookbook/embedders/together_embedder.py
from phi.agent import AgentKnowledge
from phi.vectordb.pgvector import PgVector
from phi.embedder.together import TogetherEmbedder

embeddings = TogetherEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.")

# Print the embeddings and their dimensions
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")

# Example usage:
knowledge_base = AgentKnowledge(
    vector_db=PgVector(
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
        table_name="together_embeddings",
        embedder=TogetherEmbedder(),
    ),
    num_documents=2,
)

Params

ParameterTypeDefaultDescription
modelstr"nomic-ai/nomic-embed-text-v1.5"The name of the model used for generating embeddings.
dimensionsint768The dimensionality of the embeddings generated by the model.
api_keystrThe API key used for authenticating requests.
base_urlstr"https://api.Together.ai/inference/v1"The base URL for the API endpoint.