Upstage

Qdrant 支持使用来自 Upstage 的 Solar Embeddings API。

Solar Embeddings API 具有用于用户查询和文档嵌入的双模型,在一个统一的向量空间内,专为高性能文本处理而设计。

您可以从 Upstage 控制台生成 API 密钥以验证请求。

设置 Qdrant 客户端和 Upstage 会话

import requests
from qdrant_client import QdrantClient

UPSTAGE_BASE_URL = "https://api.upstage.ai/v1/solar/embeddings"

UPSTAGE_API_KEY = "<YOUR_API_KEY>"

upstage_session = requests.Session()

client = QdrantClient(url="http://localhost:6333")

headers = {
    "Authorization": f"Bearer {UPSTAGE_API_KEY}",
    "Accept": "application/json",
}

texts = [
    "Qdrant is the best vector search engine!",
    "Loved by Enterprises and everyone building for low latency, high performance, and scale.",
]
import { QdrantClient } from '@qdrant/js-client-rest';

const UPSTAGE_BASE_URL = "https://api.upstage.ai/v1/solar/embeddings"
const UPSTAGE_API_KEY = "<YOUR_API_KEY>"

const client = new QdrantClient({ url: 'http://localhost:6333' });

const headers = {
    "Authorization": "Bearer " + UPSTAGE_API_KEY,
    "Accept": "application/json",
    "Content-Type": "application/json"
}

const texts = [
    "Qdrant is the best vector search engine!",
    "Loved by Enterprises and everyone building for low latency, high performance, and scale.",
]

以下示例展示了如何使用推荐的 `solar-embedding-1-large-passage` 和 `solar-embedding-1-large-query` 模型嵌入文档,这些模型生成大小为 4096 的句子嵌入。

嵌入文档

body = {
    "input": texts,
    "model": "solar-embedding-1-large-passage",
}

response_body = upstage_session.post(
    UPSTAGE_BASE_URL, headers=headers, json=body
).json()
let body = {
    "input": texts,
    "model": "solar-embedding-1-large-passage",
}

let response = await fetch(UPSTAGE_BASE_URL, {
    method: "POST",
    body: JSON.stringify(body),
    headers
});

let response_body = await response.json()

将模型输出转换为 Qdrant 点

from qdrant_client.models import PointStruct

points = [
    PointStruct(
        id=idx,
        vector=data["embedding"],
        payload={"text": text},
    )
    for idx, (data, text) in enumerate(zip(response_body["data"], texts))
]
let points = response_body.data.map((data, i) => {
    return {
        id: i,
        vector: data.embedding,
        payload: {
            text: texts[i]
        }
    }
})

创建一个集合来插入文档

from qdrant_client.models import VectorParams, Distance

collection_name = "example_collection"

client.create_collection(
    collection_name,
    vectors_config=VectorParams(
        size=4096,
        distance=Distance.COSINE,
    ),
)
client.upsert(collection_name, points)
const COLLECTION_NAME = "example_collection"

await client.createCollection(COLLECTION_NAME, {
    vectors: {
        size: 4096,
        distance: 'Cosine',
    }
});

await client.upsert(COLLECTION_NAME, {
    wait: true,
    points
})

使用 Qdrant 搜索文档

添加所有文档后,您可以搜索最相关的文档。

body = {
    "input": "What is the best to use for vector search scaling?",
    "model": "solar-embedding-1-large-query",
}

response_body = upstage_session.post(
    UPSTAGE_BASE_URL, headers=headers, json=body
).json()

client.search(
    collection_name=collection_name,
    query_vector=response_body["data"][0]["embedding"],
)
body = {
    "input": "What is the best to use for vector search scaling?",
    "model": "solar-embedding-1-large-query",
}

response = await fetch(UPSTAGE_BASE_URL, {
    method: "POST",
    body: JSON.stringify(body),
    headers
});

response_body = await response.json()

await client.search(COLLECTION_NAME, {
    vector: response_body.data[0].embedding,
});
此页面有帮助吗?

感谢您的反馈!🙏

很抱歉听到这个消息。😔 您可以在 GitHub 上编辑此页面,或创建 GitHub Issue。