|
|
RAG with Property Graphs using LlamaIndex
Author: Venkata Sudhakar
ShopMax India needs to query complex relationships across product specs, supplier agreements, and warranty documents while preserving entity context. LlamaIndex's PropertyGraphIndex builds a property graph directly from documents by extracting entities and relationships using an LLM, storing them for hybrid graph and vector retrieval without requiring a separate graph database setup.
PropertyGraphIndex uses an LLM to extract entities and relationships as it indexes documents, storing them as nodes and typed edges in a property graph. At query time it can retrieve using graph traversal, vector similarity, or both. It supports in-memory SimpleGraphStore for development and Neo4j or Nebula Graph for production. The LLM uses the graph structure to answer relationship-heavy questions accurately.
The below example shows how ShopMax India builds a PropertyGraphIndex from product and supplier documents using LlamaIndex with SimpleLLMPathExtractor.
It gives the following output,
Samsung products at ShopMax India are supplied by two primary partners:
Mehta Electronics (Mumbai, Delhi) and Sunrise Distributors (Bangalore,
Hyderabad, Chennai). Warranty terms vary: Mehta Electronics offers
same-day replacement for DOA units, while Sunrise Distributors processes
replacements within 5 business days. Both partners cover manufacturing
defects for 1 year under the standard Samsung India warranty.
SimpleLLMPathExtractor makes one LLM call per chunk - for large document sets at ShopMax India, use ImplicitPathExtractor first (no LLM calls, uses noun phrases) to build a draft graph cheaply, then enrich only high-value documents with SimpleLLMPathExtractor. Persist the index with storage_context.persist() so you do not re-index on every restart. Switch to Neo4jPropertyGraphStore for production to enable persistent, queryable graph storage beyond the session.
|
|