Text2Vec
A Text2Vec embedding function turns text (sentences, paragraphs, or words) into numeric vectors ("embeddings"). Those vectors encode semantic information so systems can understand and compare similarity between texts.
Text2Vec offers multilingual support (100+ languages) and several pretrained models for tasks such as text classification, semantic similarity, retrieval, and clustering.
This embedding function is often used as the model input layer when building semantic similarity models, recommendation systems, question answering, and similar applications.
Dependencies and environment
-
The
pyseekdbpackage is installed. -
Text2Vec is installed.
pip install text2vec
Example: create a Text2Vec embedding function
-
Generate text embeddings with the default model
import pyseekdb
from pyseekdb.utils.embedding_functions import Text2VecEmbeddingFunction
from text2vec import SentenceModel
model = SentenceModel()
ef = Text2VecEmbeddingFunction(model=model) -
Use a custom
api_key_envimport pyseekdb
from pyseekdb.utils.embedding_functions import Text2VecEmbeddingFunction
from text2vec import SentenceModel
model = SentenceModel("shibing624/text2vec-base-chinese")
ef = Text2VecEmbeddingFunction(model=model, api_key_env="OPENAI_API_KEY")
Parameters:
-
model_name(str, optional): Text2Vec embedding model name. -
kwargs: Additional arguments passed to the OpenAI client.Common options:
timeout: Request timeout in seconds.max_retries: Maximum number of retries.