llama-index packs nebulagraph_query_engine integration
Project description
NebulaGraph Query Engine Pack
This LlamaPack creates a NebulaGraph query engine, and executes its query
function. This pack offers the option of creating multiple types of query engines, namely:
- Knowledge graph vector-based entity retrieval (default if no query engine type option is provided)
- Knowledge graph keyword-based entity retrieval
- Knowledge graph hybrid entity retrieval
- Raw vector index retrieval
- Custom combo query engine (vector similarity + KG entity retrieval)
- KnowledgeGraphQueryEngine
- KnowledgeGraphRAGRetriever
CLI Usage
You can download llamapacks directly using llamaindex-cli
, which comes installed with the llama-index
python package:
llamaindex-cli download-llamapack NebulaGraphQueryEnginePack --download-dir ./nebulagraph_pack
You can then inspect the files at ./nebulagraph_pack
and use them as a template for your own project!
Code Usage
You can download the pack to a ./nebulagraph_pack
directory:
from llama_index.core.llama_pack import download_llama_pack
# download and install dependencies
NebulaGraphQueryEnginePack = download_llama_pack(
"NebulaGraphQueryEnginePack", "./nebulagraph_pack"
)
From here, you can use the pack, or inspect and modify the pack in ./nebulagraph_pack
.
Then, you can set up the pack like so:
pip install llama-index-readers-wikipedia
# Load the docs (example of Paleo diet from Wikipedia)
from llama_index.readers.wikipedia import WikipediaReader
loader = WikipediaReader()
docs = loader.load_data(pages=["Paleolithic diet"], auto_suggest=False)
print(f"Loaded {len(docs)} documents")
# get NebulaGraph credentials (assume it's stored in credentials.json)
with open("credentials.json") as f:
nebulagraph_connection_params = json.load(f)
username = nebulagraph_connection_params["username"]
password = nebulagraph_connection_params["password"]
ip_and_port = nebulagraph_connection_params["ip_and_port"]
space_name = "paleo_diet"
edge_types, rel_prop_names = ["relationship"], ["relationship"]
tags = ["entity"]
max_triplets_per_chunk = 10
# create the pack
nebulagraph_pack = NebulaGraphQueryEnginePack(
username=username,
password=password,
ip_and_port=ip_and_port,
space_name=space_name,
edge_types=edge_types,
rel_prop_names=rel_prop_names,
tags=tags,
max_triplets_per_chunk=max_triplets_per_chunk,
docs=docs,
)
Optionally, you can pass in the query_engine_type
from NebulaGraphQueryEngineType
to construct NebulaGraphQueryEnginePack
. If query_engine_type
is not defined, it defaults to Knowledge Graph vector based entity retrieval.
from llama_index.core.packs.nebulagraph_query_engine.base import (
NebulaGraphQueryEngineType,
)
# create the pack
nebulagraph_pack = NebulaGraphQueryEnginePack(
username=username,
password=password,
ip_and_port=ip_and_port,
space_name=space_name,
edge_types=edge_types,
rel_prop_names=rel_prop_names,
tags=tags,
max_triplets_per_chunk=max_triplets_per_chunk,
docs=docs,
query_engine_type=NebulaGraphQueryEngineType.KG_HYBRID,
)
NebulaGraphQueryEnginePack
is a enum defined as follows:
class NebulaGraphQueryEngineType(str, Enum):
"""NebulaGraph query engine type"""
KG_KEYWORD = "keyword"
KG_HYBRID = "hybrid"
RAW_VECTOR = "vector"
RAW_VECTOR_KG_COMBO = "vector_kg"
KG_QE = "KnowledgeGraphQueryEngine"
KG_RAG_RETRIEVER = "KnowledgeGraphRAGRetriever"
The run()
function is a light wrapper around query_engine.query()
, see a sample query below.
response = nebulagraph_pack.run("Tell me about the benefits of paleo diet.")
You can also use modules individually.
# call the query_engine.query()
query_engine = nebulagraph_pack.query_engine
response = query_engine.query("query_str")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file llama_index_packs_nebulagraph_query_engine-0.4.0.tar.gz
.
File metadata
- Download URL: llama_index_packs_nebulagraph_query_engine-0.4.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 840723f5e8dad73a455fccbe6ab33d1670bf25c9ad29df4f221753c2d89392ef |
|
MD5 | 8b3455d39ee57d45a51d1e1bb5bf9621 |
|
BLAKE2b-256 | e932645caf90578688ccaffc117bb0caa552aff0f73033b8e4aec93a6b970e02 |
File details
Details for the file llama_index_packs_nebulagraph_query_engine-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_packs_nebulagraph_query_engine-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 155cccd082090f7e0aa518ffe185032fa88c91d7cdb7dc9c4e10d86ce9a0d747 |
|
MD5 | 04264fd763acd871e4ff2d031d769a9d |
|
BLAKE2b-256 | 5e6afb8ef652aead5a3494486f832c20534254e589fc848f758943351f19d223 |