Skip to main content

Lexical Graph

The lexical-graph package provides a framework for automating the construction of a hierarchical lexical graph from unstructured data, and composing question-answering strategies that query this graph when answering user questions.

Features

Installation

The lexical-graph requires Python 3.10 or greater and pip.

Install the latest stable release from PyPI:

$ pip install graphrag-lexical-graph

To install a specific version from PyPI:

$ pip install graphrag-lexical-graph==3.19.0

Or install from a release zip file:

$ pip install https://github.com/awslabs/graphrag-toolkit/archive/refs/tags/graphrag-lexical-graph/v3.19.0.zip#subdirectory=lexical-graph

If you're running on AWS, you must run your application in an AWS region containing the Amazon Bedrock foundation models used by the lexical graph (see the configuration section in the documentation for details on the default models used), and must enable access to these models before running any part of the solution.

Additional dependencies

You will need to install additional dependencies for specific graph and vector store backends:

Amazon OpenSearch Serverless

$ pip install opensearch-py llama-index-vector-stores-opensearch

Postgres with pgvector

$ pip install psycopg2-binary pgvector

Neo4j

$ pip install neo4j

Connection strings

Pass a connection string to GraphStoreFactory.for_graph_store() or VectorStoreFactory.for_vector_store() to select a backend:

Store Connection string
Neptune Analytics (graph) neptune-graph://<graph-id>
Neptune Database (graph) neptune-db://<hostname> or any hostname ending .neptune.amazonaws.com
Neo4j (graph) bolt://, bolt+ssc://, bolt+s://, neo4j://, neo4j+ssc://, or neo4j+s:// URLs
OpenSearch Serverless (vector) aoss://<url>
Neptune Analytics (vector) neptune-graph://<graph-id>
pgvector (vector) constructed via PGVectorIndexFactory
S3 Vectors (vector) constructed via S3VectorIndexFactory
Dummy / no-op None or any unrecognised string — falls back to DummyGraphStore / DummyVectorIndex

Example of use

Indexing

from graphrag_toolkit.lexical_graph import LexicalGraphIndex
from graphrag_toolkit.lexical_graph.storage import GraphStoreFactory
from graphrag_toolkit.lexical_graph.storage import VectorStoreFactory

# requires pip install llama-index-readers-web
from llama_index.readers.web import SimpleWebPageReader

def run_extract_and_build():

    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
        )

        doc_urls = [
            'https://docs.aws.amazon.com/neptune/latest/userguide/intro.html',
            'https://docs.aws.amazon.com/neptune-analytics/latest/userguide/what-is-neptune-analytics.html',
            'https://docs.aws.amazon.com/neptune-analytics/latest/userguide/neptune-analytics-features.html',
            'https://docs.aws.amazon.com/neptune-analytics/latest/userguide/neptune-analytics-vs-neptune-database.html'
        ]

        docs = SimpleWebPageReader(
            html_to_text=True,
            metadata_fn=lambda url:{'url': url}
        ).load_data(doc_urls)

        graph_index.extract_and_build(docs, show_progress=True)

if __name__ == '__main__':
    run_extract_and_build()

Querying

from graphrag_toolkit.lexical_graph import LexicalGraphQueryEngine
from graphrag_toolkit.lexical_graph.storage import GraphStoreFactory
from graphrag_toolkit.lexical_graph.storage import VectorStoreFactory

def run_query():

    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
    ):

        query_engine = LexicalGraphQueryEngine.for_traversal_based_search(
            graph_store,
            vector_store
        )

        response = query_engine.query('''What are the differences between Neptune Database
                                         and Neptune Analytics?''')

        print(response.response)

if __name__ == '__main__':
    run_query()

Documentation

Release

Release instructions are found in the RELEASE.md

License

This project is licensed under the Apache-2.0 License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphrag_lexical_graph-3.19.0.tar.gz (558.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphrag_lexical_graph-3.19.0-py3-none-any.whl (533.4 kB view details)

Uploaded Python 3

File details

Details for the file graphrag_lexical_graph-3.19.0.tar.gz.

File metadata

  • Download URL: graphrag_lexical_graph-3.19.0.tar.gz
  • Upload date:
  • Size: 558.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for graphrag_lexical_graph-3.19.0.tar.gz
Algorithm Hash digest
SHA256 c4ebfc4900e25ea6f64a036825ccaec09aef13cd5630afcb2a90396811cddcc5
MD5 a141a2098cb14da6aacbec59a0e900de
BLAKE2b-256 233aef388db915008a76779c907c4856543ec0b87df06af8c4d7f971f6f0b04e

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrag_lexical_graph-3.19.0.tar.gz:

Publisher: lexical-graph-release.yml on awslabs/graphrag-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file graphrag_lexical_graph-3.19.0-py3-none-any.whl.

File metadata

File hashes

Hashes for graphrag_lexical_graph-3.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a4cb55dc8ef1a01bdf5f9e394a5afe6aa113c12fb731153bbac45173b69a771
MD5 46c3a9b7c63d6aff5de65d25bdc0d1ae
BLAKE2b-256 f5c453e7e989d51ce55c0468f5c99990abb19c321e0867d7fdcc2b66bb859a1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrag_lexical_graph-3.19.0-py3-none-any.whl:

Publisher: lexical-graph-release.yml on awslabs/graphrag-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

3.19.1

2 files

This release

3.19.0 This release

2 files

3.18.7

2 files

3.18.6

2 files

3.18.5

2 files

3.18.3

2 files

3.18.2

2 files

3.18.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page