CAB*_*CAB 2 information-retrieval langchain
我正在使用 langchain 库将我公司的信息保存在矢量数据库中,当我查询信息时,结果很好,但也需要一种方法来恢复信息的来源 - 例如来源:“www.site.txt”。 com/about”或至少“文档 156”。你们有人知道该怎么做吗?
编辑:目前,我正在使用docsearch.similarity_search(query),只返回 page_content,但元数据为空
我正在吸收这段代码,但我完全愿意改变。
db = ElasticVectorSearch.from_documents(
documents,
embeddings,
elasticsearch_url="http://localhost:9200",
index_name="elastic-index",
)
Run Code Online (Sandbox Code Playgroud)
您可以通过将每个文档设置document.metadata为字典来将元数据添加到每个文档。字典可以是类似{"source": "www.site.com/about"}或 的东西{"id": "456"},举一些例子。然后,将这些文档传递给from_documents().
稍后,当您Document从其中一种查询方法取回对象时,您可以使用document.metadata来取回元数据。