Skip to content

Graph-enhanced
retrieval for
generative AI.

An open-source Python toolkit from AWS Labs for building hierarchical lexical graphs and querying them with multi-strategy retrieval.

Lexical Graph

Automate the construction of a hierarchical lexical graph from unstructured documents, then query it with semantic-guided or traversal-based retrieval.

BYOKG-RAG

Bring your own knowledge graph. Plug an existing graph into a multi-strategy KGQA pipeline without re-extracting anything.

Pluggable storage

Graph stores: Amazon Neptune (DB and Analytics), Neo4j, FalkorDB. Vector stores: Neptune, OpenSearch, Postgres, S3 Vectors.

Open source

Apache 2.0, developed in the open by AWS Labs.

Terminal window
pip install graphrag-lexical-graph
extract_and_build.py
from graphrag_toolkit.lexical_graph import LexicalGraphIndex
from graphrag_toolkit.lexical_graph.storage import GraphStoreFactory, VectorStoreFactory
from llama_index.readers.web import SimpleWebPageReader
with (
GraphStoreFactory.for_graph_store(
'neptune-db://my-graph.cluster-abcdefghijkl.us-east-1.neptune.amazonaws.com'
) as graph_store,
VectorStoreFactory.for_vector_store(
'aoss://https://abcdefghijkl.us-east-1.aoss.amazonaws.com'
) as vector_store,
):
graph_index = LexicalGraphIndex(graph_store, vector_store)
docs = SimpleWebPageReader(html_to_text=True).load_data([
'https://docs.aws.amazon.com/neptune/latest/userguide/intro.html',
])
graph_index.extract_and_build(docs, show_progress=True)