GraphRAG Accelerator

repository·main·Indexed 25 days ago

https://github.com/azure-samples/graphrag-accelerator

A hosted, scalable API implementation of Microsoft's GraphRAG. It includes a FastAPI backend (graphrag-app v1.2.0) that serves as a REST API wrapper around the official GraphRAG library, a Streamlit-based frontend UI, and infrastructure for deployment via Helm charts or as an Azure Managed App.

Tokens
16.3K
Snippets
36
Records
90
Agent score
81%

What's inside graphrag-accelerator

  1. Overview of GraphRAG Accelerator

    main

    The GraphRAG Accelerator is a solution built on top of the graphrag Python package. It exposes API endpoints hosted on Azure to trigger indexing pipelines and enable querying of a GraphRAG knowledge graph. It is designed to host a high-utilization API with auto-scaling and user access control, using knowledge graph memory structures to enhance LLM outputs.

    Important Considerations:

    • Cost Warning: The accelerator uses multiple Azure services and GraphRAG indexing can be an expensive operation. It is recommended to start with a small amount of data.
    • Maintenance Status: This repository is no longer maintained. For future updates and continued collaboration, visit the official graphrag library.
  2. Overview of the GraphRAG Web App

    main
    The backend directory contains a FastAPI application that serves as a REST API wrapper around the graphrag library. The application is structured as a Python package to facilitate streamlined installation and deployment. It provides endpoints for interacting with GraphRAG capabilities via a RESTful interface.
  3. Configure Azure OpenAI (AOAI) requirements

    main

    You must have an existing Azure OpenAI resource or sufficient quota to deploy a new one. The AOAI instance must reside in the same subscription as the GraphRAG deployment.

    If deploying a new instance, the accelerator uses default models. Recommended quota thresholds for smooth operation:

    Model NameTPM Threshold
    gpt-4 turbo80K
    text-embedding-ada-002300K
  4. Understand the core capabilities and use cases of GraphRAG

    main

    GraphRAG is an AI-based content interpretation and search capability that uses LLMs to parse data into a knowledge graph. This allows it to answer questions about private datasets by connecting information across large volumes of data.

    Key Capabilities

    • Cross-document reasoning: Connects information that spans many documents, which is often difficult for standard keyword or vector-based search.
    • Thematic analysis: Answers abstract or high-level questions, such as "what are the top themes in this dataset?".
    • Complex discovery: Supports information discovery in noisy datasets or those containing misinformation.

    Intended Use Cases

    • Critical information discovery where insights require synthesizing data from many sources.
    • Scenarios where users are trained in responsible analytic approaches and can perform human verification of generated responses.
  5. Understand the backend package layout

    main

    The backend application follows this directory structure:

    • graphrag_app/: The core Python package containing the application logic.
      • api/: Contains the REST endpoint definitions.
      • logger/: Custom loggers optimized for graphrag usage.
      • main.py: The entry point that initializes the FastAPI application.
      • typing/: Data validation models (likely Pydantic models).
      • utils/: Helper and utility functions.
    • manifests/: Kubernetes (k8s) manifest files for deployment.
    • scripts/: Miscellaneous scripts executed within the Kubernetes environment.
    • tests/: Integration and unit tests using pytest.
    backend
    ├── README.md
    ├── graphrag_app     # contains the main application files
    │   ├── __init__.py
    │   ├── api          # endpoint definitions
    │   ├── logger       # custom loggers designed for graphrag use
    │   ├── main.py      # initializes the FastAPI application
    │   ├── typing       # data validation models
    │   └── utils        # utility/helper functions
    ├── manifests        # k8s manifest files
    ├── poetry.lock
    ├── pyproject.toml
    ├── pytest.ini
    ├── scripts          # miscellaneous scripts that get executed in k8s
    └── tests            # pytests (integration tests + unit tests)
  6. Quickstart with GraphRAG API calls

    main

    Once the solution has been deployed, you can use the provided Jupyter notebook to demonstrate and test various API calls. This notebook serves as a practical guide for interacting with the deployed GraphRAG endpoints.

    Refer to: notebooks/1-Quickstart.ipynb

  7. Implement safety and content filtering for GraphRAG

    main

    While GraphRAG is designed to be resilient to prompt and data corpus injection attacks, the underlying LLM configured by the user may still produce inappropriate or offensive content.

    • Use Safety Classifiers: Developers should assess outputs for their specific context and use available safety classifiers.
    • Model-Specific Filters: Utilize model-specific safety filters and features (e.g., Azure AI Content Safety).
    • Prevent Attacks: The use of content safety filters is recommended to prevent XPIA (Cross-Prompt Injection Attacks) and UPIA (User-Prompt Injection Attacks), as well as to limit harmful content generation from malicious users.
  8. Deploy the GraphRAG solution accelerator

    main

    Run the deployment script from the infra directory. The first deployment typically takes 40-50 minutes. If a deployment fails (e.g., due to quota issues), rerunning the command with the same resource group will be faster as it only attempts to deploy missing resources.

    cd infra
    bash deploy.sh -h # view help menu for additional options
    bash deploy.sh -p deploy.parameters.json
  9. Create a demonstration dataset using get-wiki-articles.py

    main

    To prepare data for testing the GraphRAG API, you can use the get-wiki-articles.py script to download Wikipedia articles. This allows you to work with a controlled dataset without providing your own files immediately.

    To download a standard set of articles into a directory named testdata, run:

    python get-wiki-articles.py testdata

    For a faster demonstration with minimal data, use the --short-summary and --num-articles flags to download only a single article with brief content:

    python get-wiki-articles.py --short-summary --num-articles 1 testdata
    python get-wiki-articles.py testdata