Weaviate 读取器¶
In [ ]
已复制!
%pip install llama-index-readers-weaviate
%pip install llama-index-readers-weaviate
In [ ]
已复制!
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 上打开此 Notebook,则可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
!pip install llama-index
!pip install llama-index
In [ ]
已复制!
import weaviate
from llama_index.readers.weaviate import WeaviateReader
import weaviate from llama_index.readers.weaviate import WeaviateReader
In [ ]
已复制!
# See https://weaviate.io/developers/weaviate/client-libraries/python
# for more details on authentication
resource_owner_config = weaviate.AuthClientPassword(
username="<username>",
password="<password>",
)
# initialize reader
reader = WeaviateReader(
"https://<cluster-id>.semi.network/",
auth_client_secret=resource_owner_config,
)
# 有关身份验证的更多详细信息,请参阅 https://weaviate.io/developers/weaviate/client-libraries/python # for more details on authentication resource_owner_config = weaviate.AuthClientPassword( username="", password="", ) # initialize reader reader = WeaviateReader( "https://.semi.network/", auth_client_secret=resource_owner_config, )
对于 Weaviate 读取器,您有两个选项:1) 直接指定 class_name 和 properties,或 2) 输入原始 graphql_query。示例如下所示。
In [ ]
已复制!
# 1) load data using class_name and properties
# docs = reader.load_data(
# class_name="Author", properties=["name", "description"], separate_documents=True
# )
documents = reader.load_data(
class_name="<class_name>",
properties=["property1", "property2", "..."],
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=["property1", "property2", "..."], separate_documents=True, )
In [ ]
已复制!
# 2) example GraphQL query
# query = """
# {
# Get {
# Author {
# name
# description
# }
# }
# }
# """
# docs = reader.load_data(graphql_query=query, separate_documents=True)
query = """
{
Get {
<class_name> {
<property1>
<property2>
...
}
}
}
"""
documents = reader.load_data(graphql_query=query, separate_documents=True)
# 2) GraphQL 查询示例 # query = """ # { # Get { # Author { # name # description # } # } # } # """ # docs = reader.load_data(graphql_query=query, separate_documents=True) query = """ { Get { {
... } } } """ documents = reader.load_data(graphql_query=query, separate_documents=True)
创建索引¶
In [ ]
已复制!
index = SummaryIndex.from_documents(documents)
index = SummaryIndex.from_documents(documents)
In [ ]
已复制!
# set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine()
response = query_engine.query("<query_text>")
# 将 Logging 设置为 DEBUG 以获得更详细的输出 query_engine = index.as_query_engine() response = query_engine.query("")
In [ ]
已复制!
display(Markdown(f"<b>{response}</b>"))
display(Markdown(f"{response}"))