[Doc] Document Matryoshka Representation Learning support (#16770)

This commit is contained in:
wang.yuqi
2025-04-17 21:37:37 +08:00
committed by GitHub
parent dbe7f07001
commit 11c3b98491
2 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,36 @@
# SPDX-License-Identifier: Apache-2.0
"""Example Python client for embedding API dimensions using vLLM API server
NOTE:
start a supported Matryoshka Embeddings model server with `vllm serve`, e.g.
vllm serve jinaai/jina-embeddings-v3 --trust-remote-code
"""
from openai import OpenAI
# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
def main():
client = OpenAI(
# defaults to os.environ.get("OPENAI_API_KEY")
api_key=openai_api_key,
base_url=openai_api_base,
)
models = client.models.list()
model = models.data[0].id
responses = client.embeddings.create(
input=["Follow the white rabbit."],
model=model,
dimensions=1,
)
for data in responses.data:
print(data.embedding) # List of float of len 1
if __name__ == "__main__":
main()