Skip to content

Commit

Permalink
Update llamaindex.adoc
Browse files Browse the repository at this point in the history
added example
  • Loading branch information
jexp authored Feb 28, 2024
1 parent c92e8b6 commit ebe18b6
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions modules/genai-ecosystem/pages/llamaindex.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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^]
Expand Down

0 comments on commit ebe18b6

Please sign in to comment.