Skip to main content

llama-index packs neo4j_query_engine integration

Project description

Neo4j Query Engine Pack

This LlamaPack creates a Neo4j 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 Neo4jQueryEnginePack --download-dir ./neo4j_pack

You can then inspect the files at ./neo4j_pack and use them as a template for your own project!

Code Usage

You can download the pack to a ./neo4j_pack directory:

from llama_index.core.llama_pack import download_llama_pack

# download and install dependencies
Neo4jQueryEnginePack = download_llama_pack(
    "Neo4jQueryEnginePack", "./neo4j_pack"
)

From here, you can use the pack, or inspect and modify the pack in ./neo4j_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 Neo4j credentials (assume it's stored in credentials.json)
with open("credentials.json") as f:
    neo4j_connection_params = json.load(f)
    username = neo4j_connection_params["username"]
    password = neo4j_connection_params["password"]
    url = neo4j_connection_params["url"]
    database = neo4j_connection_params["database"]

# create the pack
neo4j_pack = Neo4jQueryEnginePack(
    username=username, password=password, url=url, database=database, docs=docs
)

Optionally, you can pass in the query_engine_type from Neo4jQueryEngineType to construct Neo4jQueryEnginePack. If query_engine_type is not defined, it defaults to Knowledge Graph vector based entity retrieval.

from llama_index.core.packs.neo4j_query_engine.base import Neo4jQueryEngineType

# create the pack
neo4j_pack = Neo4jQueryEnginePack(
    username=username,
    password=password,
    url=url,
    database=database,
    docs=docs,
    query_engine_type=Neo4jQueryEngineType.KG_HYBRID,
)

Neo4jQueryEnginePack is a enum defined as follows:

class Neo4jQueryEngineType(str, Enum):
    """Neo4j 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 = neo4j_pack.run("Tell me about the benefits of paleo diet.")

You can also use modules individually.

# call the query_engine.query()
query_engine = neo4j_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

llama_index_packs_neo4j_query_engine-0.4.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_packs_neo4j_query_engine-0.4.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_packs_neo4j_query_engine-0.4.1.tar.gz
Algorithm Hash digest
SHA256 1c906f8231980f647f9dc4b90dfef3bf5cb143b408c29ed9d4e05f431ea4f2ac
MD5 f2617c76c5a7a9272ae439495c73c010
BLAKE2b-256 59259466cc62f8e663698d8060465d8e185d4cbab87318b11f4b9723e33d79b8

See more details on using hashes here.

File details

Details for the file llama_index_packs_neo4j_query_engine-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_packs_neo4j_query_engine-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d57af6bb628a736117f1c7f142b130258ff0c37fb983c83d3c407d975077a95
MD5 e286223d96c45c03bfdf0c6f3af81892
BLAKE2b-256 84ef977bce563fe98358d39d2856137f8d9bd07f9131673a774e5744a4697baf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page