Skip to main content

AwaDB

AwaDB 是一个用于搜索和存储大型语言模型应用程序所使用的嵌入向量的AI原生数据库。

您需要使用 pip install -qU langchain-community 安装 langchain-community 才能使用此集成。

本笔记本展示了如何使用与 AwaDB 相关的功能。

%pip install --upgrade --quiet  awadb
<!--IMPORTS:[{"imported": "TextLoader", "source": "langchain_community.document_loaders", "docs": "https://python.langchain.com/api_reference/community/document_loaders/langchain_community.document_loaders.text.TextLoader.html", "title": "AwaDB"}, {"imported": "AwaDB", "source": "langchain_community.vectorstores", "docs": "https://python.langchain.com/api_reference/community/vectorstores/langchain_community.vectorstores.awadb.AwaDB.html", "title": "AwaDB"}, {"imported": "CharacterTextSplitter", "source": "langchain_text_splitters", "docs": "https://python.langchain.com/api_reference/text_splitters/character/langchain_text_splitters.character.CharacterTextSplitter.html", "title": "AwaDB"}]-->
from langchain_community.document_loaders import TextLoader
from langchain_community.vectorstores import AwaDB
from langchain_text_splitters import CharacterTextSplitter
loader = TextLoader("../../how_to/state_of_the_union.txt")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=100, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
db = AwaDB.from_documents(docs)
query = "What did the president say about Ketanji Brown Jackson"
docs = db.similarity_search(query)
print(docs[0].page_content)
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.

带分数的相似性搜索

返回的距离分数在0-1之间。0表示不相似,1表示最相似

docs = db.similarity_search_with_score(query)
print(docs[0])
(Document(page_content='And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': '../../how_to/state_of_the_union.txt'}), 0.561813814013747)

恢复之前创建并添加数据的表

AwaDB会自动持久化添加的文档数据。

如果您可以恢复之前创建并添加的表,可以按如下方式操作:

import awadb

awadb_client = awadb.Client()
ret = awadb_client.Load("langchain_awadb")
if ret:
print("awadb load table success")
else:
print("awadb load table failed")

awadb 加载表成功

相关


Was this page helpful?


You can also leave detailed feedback on GitHub.

扫我,入群扫我,找书