Weaviate Reader¶
In [ ]:
Copied!
%pip install llama-index-readers-weaviate
%pip install llama-index-readers-weaviate
In [ ]:
Copied!
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
如果您在colab上打开这个笔记本,您可能需要安装LlamaIndex 🦙。
In [ ]:
Copied!
!pip install llama-index
!pip install llama-index
In [ ]:
Copied!
import weaviate
from llama_index.readers.weaviate import WeaviateReader
import weaviate
from llama_index.readers.weaviate import WeaviateReader
In [ ]:
Copied!
# 有关身份验证的更多详细信息,请参阅https://weaviate.io/developers/weaviate/current/client-libraries/python.html
resource_owner_config = weaviate.AuthClientPassword(
username="<用户名>",
password="<密码>",
)
# 初始化读取器
reader = WeaviateReader(
"https://<cluster-id>.semi.network/",
auth_client_secret=resource_owner_config,
)
# 有关身份验证的更多详细信息,请参阅https://weaviate.io/developers/weaviate/current/client-libraries/python.html
resource_owner_config = weaviate.AuthClientPassword(
username="<用户名>",
password="<密码>",
)
# 初始化读取器
reader = WeaviateReader(
"https://.semi.network/",
auth_client_secret=resource_owner_config,
)
您有两种选项可以使用Weaviate阅读器:1)直接指定class_name和properties,或者2)输入原始的graphql_query。下面展示了示例。
In [ ]:
Copied!
# 1) 使用class_name和properties加载数据
# docs = reader.load_data(
# class_name="Author", properties=["name", "description"], separate_documents=True
# )
documents = reader.load_data(
class_name="<类名>",
properties=["属性1", "属性2", "…"],
separate_documents=True,
)
# 1) 使用class_name和properties加载数据
# docs = reader.load_data(
# class_name="Author", properties=["name", "description"], separate_documents=True
# )
documents = reader.load_data(
class_name="<类名>",
properties=["属性1", "属性2", "…"],
separate_documents=True,
)
In [ ]:
Copied!
# 2) 示例 GraphQL 查询
# 查询 = """
# {
# Get {
# 作者 {
# 名字
# 描述
# }
# }
# }
# """
# 文档 = reader.load_data(graphql_query=query, separate_documents=True)
查询 = """
{
Get {
<类名> {
<属性1>
<属性2>
...
}
}
}
"""
文档 = reader.load_data(graphql_query=query, separate_documents=True)
# 2) 示例 GraphQL 查询
# 查询 = """
# {
# Get {
# 作者 {
# 名字
# 描述
# }
# }
# }
# """
# 文档 = reader.load_data(graphql_query=query, separate_documents=True)
查询 = """
{
Get {
<类名> {
<属性1>
<属性2>
...
}
}
}
"""
文档 = reader.load_data(graphql_query=query, separate_documents=True)
创建索引¶
In [ ]:
Copied!
index = SummaryIndex.from_documents(documents)
index = SummaryIndex.from_documents(documents)
In [ ]:
Copied!
# 将日志级别设置为DEBUG,以获得更详细的输出
query_engine = index.as_query_engine()
response = query_engine.query("<query_text>")
# 将日志级别设置为DEBUG,以获得更详细的输出
query_engine = index.as_query_engine()
response = query_engine.query("")
In [ ]:
Copied!
display(Markdown(f"<b>{response}</b>"))
display(Markdown(f"{response}"))