-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TEIEmbeddingFunction and TEIRerankFunction with usage documentation #2998
Open
bluechanel
wants to merge
4
commits into
milvus-io:v2.5.x
Choose a base branch
from
bluechanel:add_tei_doc
base: v2.5.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
23c0160
Adding a TEI Document Signed-off-by: wileyzhang <bluechanel612@gmail.…
ef1d901
Adding a TEI Document Signed-off-by: wileyzhang <bluechanel612@gmail…
a0b412a
Adding a TEI Document Signed-off-by: wileyzhang <bluechanel612@gmail.…
92a851d
Adding a Tip Signed-off-by: wileyzhang <[email protected]>
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
site/en/embeddings/embed-with-text-embeddings-inference.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
id: embed-with-text-embeddings-inference.md | ||
order: 14 | ||
summary: This article demonstrates how to use text-embeddings-inference in Milvus to encode documents and queries into dense vectors. | ||
title: text-embeddings-inference(TEI) | ||
--- | ||
|
||
# text-embeddings-inference(TEI) | ||
|
||
Text Embeddings Inference (TEI) is a comprehensive toolkit designed for efficient deployment and serving of open source text embeddings models. It enables high-performance extraction for the most popular models, including FlagEmbedding, Ember, GTE, and E5. | ||
|
||
Key Features: | ||
- Streamlined Deployment | ||
- Efficient Resource Utilization | ||
- Dynamic Batching | ||
- Optimized Inference | ||
- Safetensors weight loading | ||
- Production-Ready | ||
|
||
💡 **Tip:** Ensure that the TEI service is running before proceeding. TEI Deployment Reference Documentation https://github.com/huggingface/text-embeddings-inference | ||
|
||
To use this feature, install the necessary dependencies: | ||
|
||
```bash | ||
pip install --upgrade pymilvus | ||
pip install "pymilvus[model]" | ||
``` | ||
|
||
Then, instantiate the __TEIEmbeddingFunction__: | ||
|
||
```python | ||
from pymilvus import model | ||
|
||
tei_ef = model.dense.TEIEmbeddingFunction( | ||
api_url='http://127.0.0.1:8000' | ||
) | ||
``` | ||
|
||
__Parameters__: | ||
|
||
- __api_url__ (_string_) | ||
|
||
TEI deployment api address. | ||
|
||
|
||
To create embeddings for documents, use the __encode_documents()__ method: | ||
|
||
```python | ||
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.", | ||
] | ||
|
||
docs_embeddings = tei_ef.encode_documents(docs) | ||
|
||
# Print embeddings | ||
print("Embeddings:", docs_embeddings) | ||
# Print dimension and shape of embeddings | ||
print("Dim:", tei_ef.dim, docs_embeddings[0].shape) | ||
``` | ||
|
||
The expected output is similar to the following: | ||
|
||
```python | ||
Embeddings: [array([-3.09392996e-02, -1.80662833e-02, 1.34775648e-02, 2.77156215e-02, | ||
-4.86349640e-03, -3.12581174e-02, -3.55921760e-02, 5.76934684e-03, | ||
2.80773244e-03, 1.35783911e-01, 3.59678417e-02, 6.17732145e-02, | ||
... | ||
-4.61330153e-02, -4.85207550e-02, 3.13997865e-02, 7.82178566e-02, | ||
-4.75336798e-02, 5.21207601e-02, 9.04406682e-02, -5.36676683e-02], | ||
dtype=float32)] | ||
Dim: 512 (512,) | ||
``` | ||
|
||
To create embeddings for queries, use the __encode_queries()__ method: | ||
|
||
```python | ||
queries = ["When was artificial intelligence founded", | ||
"Where was Alan Turing born?"] | ||
|
||
query_embeddings = tei_ef.encode_queries(queries) | ||
|
||
# Print embeddings | ||
print("Embeddings:", query_embeddings) | ||
# Print dimension and shape of embeddings | ||
print("Dim:", tei_ef.dim, query_embeddings[0].shape) | ||
``` | ||
|
||
The expected output is similar to the following: | ||
|
||
```python | ||
Embeddings: [array([-2.52114702e-02, -5.29330298e-02, 1.14570223e-02, 1.95571519e-02, | ||
-2.46500354e-02, -2.66519729e-02, -8.48201662e-03, 2.82961670e-02, | ||
-3.65092754e-02, 7.50745758e-02, 4.28900979e-02, 7.18822703e-02, | ||
... | ||
-6.76431581e-02, -6.45996556e-02, -4.67132553e-02, 4.78532910e-02, | ||
-2.31596199e-03, 4.13446948e-02, 1.06935494e-01, -1.08258888e-01], | ||
dtype=float32)] | ||
Dim: 512 (512,) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
id: rerankers-text-embeddings-inference.md | ||
order: 7 | ||
summary: Milvus supports the deployment of open source reranker models by TEI through the “TEIRerankFunction” class. This function allows you to efficiently score the relevance of query-document pairs. | ||
title: text-embeddings-inference(TEI) - Rerankers | ||
--- | ||
|
||
# text-embeddings-inference(TEI) | ||
|
||
Text Embeddings Inference (TEI) is a comprehensive toolkit designed for efficient deployment and serving of open source text embeddings models. It enables high-performance extraction for the most popular models, including bge-reranker-large, roberta-base-go_emotions. | ||
|
||
Key Features: | ||
- Streamlined Deployment | ||
- Efficient Resource Utilization | ||
- Dynamic Batching | ||
- Optimized Inference | ||
- Safetensors weight loading | ||
- Production-Ready | ||
|
||
💡 **Tip:** Ensure that the TEI service is running before proceeding. TEI Deployment Reference Documentation https://github.com/huggingface/text-embeddings-inference | ||
|
||
To use this feature, install the necessary dependencies: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A prompt has been added to indicate that a TEI server needs to be running. It also includes a reference to the TEI quick start documentation. |
||
|
||
```bash | ||
pip install --upgrade pymilvus | ||
pip install "pymilvus[model]" | ||
``` | ||
|
||
Then, instantiate the `TEIRerankFunction`: | ||
|
||
```python | ||
from pymilvus.model.reranker import TEIRerankFunction | ||
|
||
tei_rf = TEIRerankFunction( | ||
api_url='http://127.0.0.1:8000' | ||
) | ||
``` | ||
|
||
__Parameters__: | ||
|
||
- __api_url__ (_string_) | ||
|
||
TEI deployment api address. | ||
|
||
Then, use the following code to rerank documents based on the query: | ||
|
||
```python | ||
query = "What event in 1956 marked the official birth of artificial intelligence as a discipline?" | ||
|
||
documents = [ | ||
"In 1950, Alan Turing published his seminal paper, 'Computing Machinery and Intelligence,' proposing the Turing Test as a criterion of intelligence, a foundational concept in the philosophy and development of artificial intelligence.", | ||
"The Dartmouth Conference in 1956 is considered the birthplace of artificial intelligence as a field; here, John McCarthy and others coined the term 'artificial intelligence' and laid out its basic goals.", | ||
"In 1951, British mathematician and computer scientist Alan Turing also developed the first program designed to play chess, demonstrating an early example of AI in game strategy.", | ||
"The invention of the Logic Theorist by Allen Newell, Herbert A. Simon, and Cliff Shaw in 1955 marked the creation of the first true AI program, which was capable of solving logic problems, akin to proving mathematical theorems." | ||
] | ||
|
||
results = tei_rf( | ||
query=query, | ||
documents=documents, | ||
top_k=3, | ||
) | ||
|
||
for result in results: | ||
print(f"Index: {result.index}") | ||
print(f"Score: {result.score:.6f}") | ||
print(f"Text: {result.text}\n") | ||
``` | ||
|
||
The expected output is similar to the following: | ||
|
||
```python | ||
Index: 1 | ||
Score: 0.9971661 | ||
Text: The Dartmouth Conference in 1956 is considered the birthplace of artificial intelligence as a field; here, John McCarthy and others coined the term 'artificial intelligence' and laid out its basic goals. | ||
|
||
Index: 2 | ||
Score: 0.00809329 | ||
Text: In 1951, British mathematician and computer scientist Alan Turing also developed the first program designed to play chess, demonstrating an early example of AI in game strategy. | ||
|
||
Index: 0 | ||
Score: 0.002491968 | ||
Text: The invention of the Logic Theorist by Allen Newell, Herbert A. Simon, and Cliff Shaw in 1955 marked the creation of the first true AI program, which was capable of solving logic problems, akin to proving mathematical theorems. | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention that it's supposed to have a TEI server up running and point to TEI quick start doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A prompt has been added to indicate that a TEI server needs to be running. It also includes a reference to the TEI quick start documentation.