Package: llama-index-packs-nebulagraph-query-engine
NebulaGraph Query Engine PackThis LlamaPack creates a NebulaGraph query engine, and executes itsqueryfunction. 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 retrievalKnowledge graph hybrid entity retrievalRaw vector index retrievalCustom combo query engine (vector similarity + KG entity retrieval)KnowledgeGraphQueryEngineKnowledgeGraphRAGRetrieverCLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackNebulaGraphQueryEnginePack--download-dir./nebulagraph_packYou can then inspect the files at./nebulagraph_packand use them as a template for your own project!Code UsageYou can download the pack to a./nebulagraph_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesNebulaGraphQueryEnginePack=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:# Load the docs (example of Paleo diet from Wikipedia)fromllama_indeximportdownload_loaderWikipediaReader=download_loader("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)withopen("credentials.json")asf: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 packnebulagraph_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 thequery_engine_typefromNebulaGraphQueryEngineTypeto constructNebulaGraphQueryEnginePack. Ifquery_engine_typeis not defined, it defaults to Knowledge Graph vector based entity retrieval.fromllama_index.packs.nebulagraph_query_engine.baseimport(NebulaGraphQueryEngineType,)# create the packnebulagraph_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,)NebulaGraphQueryEnginePackis a enum defined as follows:classNebulaGraphQueryEngineType(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"Therun()function is a light wrapper aroundquery_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_engineresponse=query_engine.query("query_str")