AWS Builder Center

Mastering GraphRAG: Amazon Bedrock Knowledge Bases with Neptune Analytics

Discover how Amazon Bedrock Knowledge Bases with GraphRAG and Neptune Analytics transform RAG applications by automatically extracting entity relationships from documents for precise, explainable responses on complex queries like financial summaries. This hands-on guide covers setup, ingestion, API testing, and scaling for production-ready AI.

Enhance generative AI applications with GraphRAG on Amazon Bedrock Knowledge Bases, combining retrieval-augmented generation (RAG) and graph structures for more accurate, contextual responses using Amazon Neptune Analytics.youtube​aws.amazon ​

Problem & Solution

Traditional RAG struggles with complex queries requiring reasoning across multiple documents, leading to incomplete or irrelevant answers. GraphRAG solves this by automatically extracting entities and relationships from ingested documents into a knowledge graph on Amazon Neptune, enabling queries that traverse connections for comprehensive insights. Financial analysts, researchers, and enterprises benefit from explainable summaries, better entity linking, and filtered noise, as seen in processing 10K synthetic financial reports for precise cash flow analysis.

Technical Implementation

AWS Services Used:
  • Amazon Bedrock Knowledge Bases: Manages ingestion, chunking with GRAPH strategy, and Neptune integration for vector store—no graph expertise needed.
  • Amazon Neptune Analytics: Stores embeddings and graph (entities, relationships, sections) for hybrid retrieval.
  • Amazon S3: Data source for documents like financial PDFs.
  • Boto3 & Bedrock Agent Runtime: Local Python SDK for retrieve_and_generate (end-to-end) and retrieve APIs (custom control) using Claude 3 Haiku.
  • IAM Roles: Secure access for KB sync and queries.
How It Works:
  1. Upload data to S3 bucket.
  2. Create KB: BedrockKnowledgeBase(..., chunking_strategy="GRAPH", vector_store="NEPTUNE_ANALYTICS").
  3. Sync: start_ingestion_job()—auto-builds graph.
  4. Query: retrieve_and_generate fetches graph-traversed chunks, generates cited responses (e.g., "Octank Financial cash flows: $710M operating").
StepAPI/CodeOutput
Setup%pip install -r requirements.txt; boto3.client('bedrock-agent-runtime')Configured clients, KB ID stored.
Ingestupload_directory("../synthetic_dataset", bucket); knowledge_base.start_ingestion_job()Documents chunked, graphed in Neptune.
Retrieve & Generateretrieve_and_generate(input={"text": query}, knowledgeBaseId=kb_id)Semantic summaries with citations.
Retrieve Onlyretrieve(knowledgeBaseId=kb_id, retrievalQuery={"text": query})Raw chunks, scores, metadata for custom logic.

Scaling Strategy

Handles 10K+ documents initially via managed Neptune clusters (serverless scaling). Current capacity: Sync one job at a time; supports high QPS via Bedrock endpoints. Future growth: Neptune auto-scales graphs; add OpenSearch hybrid; monitor via CloudWatch; partition large corpora across multiple KBs for parallel ingestion.

Visual Documentation

1
2
3
4
5
6
7
[S3 Bucket (Financial Reports)] --> [Bedrock KB (Graph Chunking + Neptune Vector/Graph Store)]
|
v
[Retrieve/RetrieveAndGenerate API (Boto3 Local)] --> [Claude 3 Haiku] --> [Cited Response]
^
|
[Neptune Graph: Entities <--> Relationships <--> Chunks] <-- Auto-Extracted
Test query: "Summary of Octank Financial cash flows 2019" yields precise metrics ($710M operating, etc.) with graph-backed relevance. Deploy locally via Jupyter/Boto3; production via Lambda/Agents.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article