Camel

Camel 是一个 Python 框架,用于构建和使用基于 LLM 的代理来解决现实世界的任务。

Qdrant 在 Camel 中可用作存储机制,用于摄入和检索语义相似的数据。

与 Qdrant 的使用方法

  • 安装 Camel,并包含 vector-databases 额外依赖。
pip install "camel[vector-databases]"
  • 配置 QdrantStorage 类。
from camel.storages import QdrantStorage, VectorDBQuery, VectorRecord
from camel.types import VectorDistance

qdrant_storage = QdrantStorage(
    url_and_api_key=(
        "https://xyz-example.eu-central.aws.cloud.qdrant.io:6333",
        "<provide-your-own-key>",
    ),
    collection_name="{collection_name}",
    distance=VectorDistance.COSINE,
    vector_dim=384,
)

QdrantStorage 类实现了读写 Qdrant 实例的方法。此类的实例现在可以传递给检索器,以便与您的 Qdrant 集合进行交互。

qdrant_storage.add([VectorRecord(
            vector=[-0.1, 0.1, ...],
            payload={'key1': 'value1'},
        ),
        VectorRecord(
            vector=[-0.1, 0.1, ...],
            payload={'key2': 'value2'},
        ),])

query_results = qdrant_storage.query(VectorDBQuery(query_vector=[0.1, 0.2, ...], top_k=10))
for result in query_results:
    print(result.record.payload, result.similarity)

qdrant_storage.clear()
  • 在 Camel 的 Vector Retriever 中使用 QdrantStorage
from camel.embeddings import OpenAIEmbedding
from camel.retrievers import VectorRetriever

# Initialize the VectorRetriever with an embedding model
vr = VectorRetriever(embedding_model=OpenAIEmbedding())

content_input_path = "<URL-TO-SOME-RESOURCE>"

vr.process(content_input_path, qdrant_storage)

# Execute the query and retrieve results
results = vr.query("<SOME_USER_QUERY>", vector_storage)
  • Camel 还提供了一个 Auto Retriever 实现,可以处理数据的嵌入、存储和查询执行。
from camel.retrievers import AutoRetriever
from camel.types import StorageType

ar = AutoRetriever(
    url_and_api_key=(
        "https://xyz-example.eu-central.aws.cloud.qdrant.io:6333",
        "<provide-your-own-key>",
    ),
    storage_type=StorageType.QDRANT,
)

retrieved_info = ar.run_vector_retriever(
    contents=["<URL-TO-SOME-RESOURCE>"],
    query=""<SOME_USER_QUERY>"",
    return_detailed_info=True, 
)

print(retrieved_info)

您可以参考 Camel 的文档,了解有关检索机制的更多信息。

端到端示例

此页面是否有用?

感谢您的反馈!🙏

很抱歉听到您这样说。😔 您可以在 GitHub 上编辑此页面,或者创建一个 GitHub issue。