LFM2.5-Embedding-350M is a dense bi-encoder for fast multilingual retrieval. It produces a single vector per document — the smallest, fastest index — for reliable cross-lingual search across 11 languages.
Find more information about LFM2.5-Embedding-350M in our
blog post.
Make requests to embed queries and documents, and rank by cosine similarity (note the asymmetric query: / document: prompt prefixes)
1❯ uv run dense-retrieve.py
2
3Score: -0.1783 | Q: What is panda? | D: hi
4Score: 0.0511 | Q: What is panda? | D: it is a bear
5Score: 0.5657 | Q: What is panda? | D: The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.
1# /// script
2# requires-python = ">=3.10"
3# dependencies = ["numpy", "requests"]
4# ///
5
6# dense-retrieve.py
7import numpy as np, requests
8
9QUERY_PREFIX, DOC_PREFIX = "query: ", "document: "
10
11def embed(text: str) -> np.ndarray:
12 r = requests.post(
13 "http://localhost:8080/v1/embeddings",
14 json={"input": text},
15 )
16 v = np.array(r.json()["data"][0]["embedding"])
17 return v / np.linalg.norm(v)
18
19docs = [
20 "hi",
21 "it is a bear",
22 "The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.",
23]
24query = "What is panda?"
25
26q = embed(QUERY_PREFIX + query)
27for doc in docs:
28 d = embed(DOC_PREFIX + doc)
29 print(f"Score: {float(q @ d):.4f} | Q: {query} | D: {doc}")