From ebe18b6ac23f1614f5d4d463d07ee75ba7c6d24f Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Wed, 28 Feb 2024 03:56:40 +0100 Subject: [PATCH] Update llamaindex.adoc added example --- modules/genai-ecosystem/pages/llamaindex.adoc | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/modules/genai-ecosystem/pages/llamaindex.adoc b/modules/genai-ecosystem/pages/llamaindex.adoc index 18a2264..672246a 100644 --- a/modules/genai-ecosystem/pages/llamaindex.adoc +++ b/modules/genai-ecosystem/pages/llamaindex.adoc @@ -16,6 +16,58 @@ LlamaIndex provides a lot of detailed examples for GenAI application development The Neo4j integration covers both the vector store as well as query generation from natural language and knowledge graph construction. +== Example Usage + +[source,python] +---- +%pip install llama-index-llms-openai +%pip install llama-index-graph-stores-neo4j +%pip install llama-index-embeddings-openai +%pip install neo4j + +from llama_index.llms.openai import OpenAI +from llama_index.embeddings.openai import OpenAIEmbedding +from llama_index.core import ( + VectorStoreIndex, + SimpleDirectoryReader, + KnowledgeGraphIndex, + Settings +) +from llama_index.graph_stores.neo4j import Neo4jGraphStore + +llm = OpenAI(temperature=0, model="gpt-3.5-turbo") +embedding_llm = OpenAIEmbedding(model="text-embedding-ada-002") + +Settings.llm = llm +Settings.embed_model = embedding_llm +Settings.chunk_size = 512 + +documents = SimpleDirectoryReader( + "../../../../examples/paul_graham_essay/data" +).load_data() + +graph_store = Neo4jGraphStore(username=username,password=password, + url=url,database=database) + +storage_context = StorageContext.from_defaults(graph_store=graph_store) + +index = KnowledgeGraphIndex.from_documents(documents, + storage_context=storage_context, max_triplets_per_chunk=2, + include_embeddings=True +) + +query_engine = index.as_query_engine( + include_text=True, + response_mode="tree_summarize", + embedding_mode="hybrid", + similarity_top_k=5, +) + +response = query_engine.query( + "Tell me more about what the author worked on at Interleaf" +) +---- + == Documentation * https://docs.llamaindex.ai/en/latest/examples/index_structs/knowledge_graph/Neo4jKGIndexDemo.html[Neo4jKGIndexDemo^]