File size: 851 Bytes
3db4bdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Quick Start
===========

First, load one of the BGE embedding model:

.. code:: python

    from FlagEmbedding import FlagAutoModel

    model = FlagAutoModel.from_finetuned('BAAI/bge-base-en-v1.5')

.. tip::

    If there's difficulty connecting to Hugging Face, you can use the `HF mirror <https://hf-mirror.com/>`_ instead.

    .. code:: bash

        export HF_ENDPOINT=https://hf-mirror.com

Then, feed some sentences to the model and get their embeddings:

.. code:: python

    sentences_1 = ["I love NLP", "I love machine learning"]
    sentences_2 = ["I love BGE", "I love text retrieval"]
    embeddings_1 = model.encode(sentences_1)
    embeddings_2 = model.encode(sentences_2)

Once we get the embeddings, we can compute similarity by inner product:

.. code:: python

    similarity = embeddings_1 @ embeddings_2.T
    print(similarity)