Microsoft

Microsoft / e5-base-v2

Ideal for good performance while keeping with open source and minimal hardware requirements. Works well on messy data. Good for short queries expected to return medium-length text passages (1-2 paragraphs).

Introduction to e5-base-v2 embedding

e5-base-v2 is a model designed for generating text embeddings that can be used for various natural language processing (NLP) tasks, including semantic search, retrieval augmented generation (RAG) and clustering. This model is based on weakly-supervised contrastive pre-training and is particularly effective for handling messy data and short queries that return medium-length passages of text.

The model requires input texts to be prefixed with "query: " for queries and "passage: " for passages. It can be utilized through libraries such as Hugging Face's Transformers and Sentence Transformers, allowing for easy integration into applications.

Comparing e5-large-v2 and e5-base-v2:

Feature/Capabilitye5-base-v2e5-large-v2
Layers1224
Embedding Size7681024
Max Tokens512512
PerformanceGood for general text embedding tasksStrong performance on benchmarks like BEIR and MTEB, often outperforming smaller models
Input Prefix Requirement"query: " for queries, "passage: " for passages"query: " for queries, "passage: " for passages
Model LinkHugging Face E5-base-v2Hugging Face E5-large-v2

How to create embeddings with e5-base-v2

There are two primary ways to create vector embeddings:

  1. PyMilvus: the Python SDK for Milvus that seamlessly integrates the e5-base-v2 model.
  2. SentenceTransformer library: the Python library sentence-transformer.

Once the vector embeddings are generated, they can be stored in Zilliz Cloud (a fully managed vector database service powered by Milvus) and used for semantic similarity search. Here are four key steps:

  1. Sign up for a Zilliz Cloud account for free.
  2. Set up a serverless cluster and obtain the Public Endpoint and API Key.
  3. Create a vector collection and insert your vector embeddings.
  4. Run a semantic search on the stored embeddings.
from pymilvus.model.dense import SentenceTransformerEmbeddingFunction
from pymilvus import MilvusClient

ef = SentenceTransformerEmbeddingFunction("intfloat/e5-base-v2")

docs = [
   "Artificial intelligence was founded as an academic discipline in 1956.",
   "Alan Turing was the first person to conduct substantial research in AI.",
   "Born in Maida Vale, London, Turing was raised in southern England."
]

# Generate embeddings for documents
docs_embeddings = ef(docs)

queries = ["When was artificial intelligence founded",
          "Where was Alan Turing born?"]

# Generate embeddings for queries
query_embeddings = ef(queries)

# Connect to Zilliz Cloud with Public Endpoint and API Key
client = MilvusClient(
    uri=ZILLIZ_PUBLIC_ENDPOINT,
    token=ZILLIZ_API_KEY)

COLLECTION = "documents"
if client.has_collection(collection_name=COLLECTION):
    client.drop_collection(collection_name=COLLECTION)
client.create_collection(
    collection_name=COLLECTION,
    dimension=ef.dim,
    auto_id=True)

for doc, embedding in zip(docs, docs_embeddings):
    client.insert(COLLECTION, {"text": doc, "vector": embedding})
    
results = client.search(
    collection_name=COLLECTION,
    data=query_embeddings,
    consistency_level="Strong", 
    output_fields=["text"])

For more information, refer to our PyMilvus Embedding Model documentation.

from sentence_transformers import SentenceTransformer
from pymilvus import MilvusClient

model = SentenceTransformer("intfloat/e5-base-v2")

docs = [
   "Artificial intelligence was founded as an academic discipline in 1956.",
   "Alan Turing was the first person to conduct substantial research in AI.",
   "Born in Maida Vale, London, Turing was raised in southern England."
]

# Generate embeddings for documents
docs_embeddings = model.encode(docs, normalize_embeddings=True)


queries = ["When was artificial intelligence founded",
          "Where was Alan Turing born?"]

# Generate embeddings for queries
query_embeddings = model.encode(queries, normalize_embeddings=True)

# Connect to Zilliz Cloud with Public Endpoint and API Key
client = MilvusClient(
    uri=ZILLIZ_PUBLIC_ENDPOINT,
    token=ZILLIZ_API_KEY)

COLLECTION = "documents"
if client.has_collection(collection_name=COLLECTION):
    client.drop_collection(collection_name=COLLECTION)
client.create_collection(
    collection_name=COLLECTION,
    dimension=768,
    auto_id=True)

for doc, embedding in zip(docs, docs_embeddings):
    client.insert(COLLECTION, {"text": doc, "vector": embedding})
    
results = client.search(
    collection_name=COLLECTION,
    data=query_embeddings,
    consistency_level="Strong", 
    output_fields=["text"])

For more information, refer to SentenceTransformer documentation.