Metal

Metalopen in new window是一个用于ML嵌入向量的托管服务。

本文介绍了如何使用Metalopen in new window的检索器。

首先,您需要注册Metal并获取一个API密钥。您可以在此处open in new window完成注册。

# !pip install metal_sdk
from metal_sdk.metal import Metal
API_KEY = ""
CLIENT_ID = ""
INDEX_ID = ""

metal = Metal(API_KEY, CLIENT_ID, INDEX_ID);

Ingest Documents

如果您尚未设置索引,则只需要执行此操作。

metal.index( {"text": "foo1"})
metal.index( {"text": "foo"})
{'data': {'id': '642739aa7559b026b4430e42','text': 'foo',createdAt': '2023-03-31T19:51:06.748Z'}}

查询

现在我们的索引已经设置好了,我们可以设置一个检索器并开始查询。

from langchain.retrievers import MetalRetriever
retriever = MetalRetriever(metal, params={"limit": 2})
retriever.get_relevant_documents("foo1")
[Document(page_content='foo1', metadata={'dist': '1.19209289551e-07', 'id': '642739a17559b026b4430e40', 'createdAt': '2023-03-31T19:50:57.853Z'}),
 Document(page_content='foo1', metadata={'dist': '4.05311584473e-06', 'id': '642738f67559b026b4430e3c', 'createdAt': '2023-03-31T19:48:06.769Z'})]
Last Updated:
Contributors: 刘强