Cohere
Qdrant 兼容 Cohere co.embed API 及其官方 Python SDK,可以像安装其他包一样安装:
pip install cohere
由 co.embed API 返回的嵌入可以直接用于 Qdrant 客户端的调用中:
import cohere
import qdrant_client
from qdrant_client.models import Batch
cohere_client = cohere.Client("<< your_api_key >>")
qdrant_client = qdrant_client.QdrantClient()
qdrant_client.upsert(
collection_name="MyCollection",
points=Batch(
ids=[1],
vectors=cohere_client.embed(
model="large",
texts=["The best vector database"],
).embeddings,
),
)
如果您有兴趣查看使用co.embed API和Qdrant创建的端到端项目,请查看“使用Cohere和Qdrant的问答服务”文章。
嵌入 v3
Embed v3 是 Cohere 模型的新系列,于 2023 年 11 月发布。新模型需要在 API 调用中传递一个额外的参数:input_type。它决定了您想要使用嵌入的任务类型。
input_type="search_document"- 用于存储在Qdrant中的文档input_type="search_query"- 用于搜索查询以找到最相关的文档input_type="classification"- 用于分类任务input_type="clustering"- 用于文本聚类
在实现语义搜索应用程序时,例如RAG,你应该对索引文档使用input_type="search_document",对搜索查询使用input_type="search_query"。以下示例展示了如何使用Embed v3模型索引文档:
import cohere
import qdrant_client
from qdrant_client.models import Batch
cohere_client = cohere.Client("<< your_api_key >>")
client = qdrant_client.QdrantClient()
client.upsert(
collection_name="MyCollection",
points=Batch(
ids=[1],
vectors=cohere_client.embed(
model="embed-english-v3.0", # New Embed v3 model
input_type="search_document", # Input type for documents
texts=["Qdrant is the a vector database written in Rust"],
).embeddings,
),
)
一旦文档被索引,你可以使用Embed v3模型搜索最相关的文档:
client.search(
collection_name="MyCollection",
query_vector=cohere_client.embed(
model="embed-english-v3.0", # New Embed v3 model
input_type="search_query", # Input type for search queries
texts=["The best vector database"],
).embeddings[0],
)
