Skip to main content

GeminiEmbeddingFunction

Model2VecEmbeddingFunction is a class in pymilvus that handles encoding text into embeddings using the GeminiEmbeddingFunction module to support embedding retrieval in Milvus.

python
pymilvus.model.dense.GeminiEmbeddingFunction

Constructor

Constructs an GeminiEmbeddingFunction for common use cases.

python
GeminiEmbeddingFunction(
model_name: str = "gemini-embedding-exp-03-07",
api_key: Optional[str] = None,
config: Optional['types.EmbedContentConfig']=None,
**kwargs,
)

PARAMETERS:

  • model_name (string) -

    The name of the Gemini model to use for encoding. Valid options are gemini-embedding-exp-03-07(default), models/embedding-001, and models/text-embedding-004.

  • api_key (string)-

The API key for accessing the Gemini API.

  • config (types.EmbedContentConfig) -

    Optional configuration for the embedding model.

    • The output_dimensionality can be specified to the number of resulting output embeddings.

      Model NameDimensions
      emini-embedding-exp-03-073072(default),1536,768
      models/embedding-001768
      models/text-embedding-004768
    • The task_type can be specified to generate optimized embeddings for specific tasks, saving you time and cost and improving performance. Only supported in the gemini-embedding-exp-03-07 model.

      Task TypeDescription
      SEMANTIC_SIMILARITYUsed to generate embeddings that are optimized to assess text similarity.
      CLASSIFICATIONUsed to generate embeddings that are optimized to classify texts according to preset labels.
      CLUSTERINGUsed to generate embeddings that are optimized to cluster texts based on their similarities.
      RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY, QUESTION_ANSWERING, and FACT_VERIFICATIONUsed to generate embeddings that are optimized for document search or information retrieval.
      CODE_RETRIEVAL_QUERYUsed to retrieve a code block based on a natural language query, such as sort an array or reverse a linked list. Embeddings of the code blocks are computed using RETRIEVAL_DOCUMENT.

Examples

python
from pymilvus import model

gemini_ef = model.dense.GeminiEmbeddingFunction(
model_name="gemini-embedding-exp-03-07",
api_key="YOUR_API_KEY",
)
Minimum SDK versionv2.5.x
Ctrl I