repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
graphrag | packages/graphrag-storage/graphrag_storage/tables/table_provider_factory.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Storage factory implementation."""
from collections.abc import Callable
from graphrag_common.factory import Factory, ServiceScope
from graphrag_storage.storage import Storage
from graphrag_storage.tables.table_provider import TableProv... | 110 | 3,807 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/table.py | .py | # Copyright (C) 2025 Microsoft
# Licensed under the MIT License
"""Table abstraction for streaming row-by-row access."""
from abc import ABC, abstractmethod
from collections.abc import AsyncIterator, Callable
from types import TracebackType
from typing import Any
from typing_extensions import Self
RowTransformer = ... | 126 | 3,296 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/table_provider.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Abstract base class for table providers."""
from abc import ABC, abstractmethod
from typing import Any
import pandas as pd
from graphrag_storage.tables.table import RowTransformer, Table
class TableProvider(ABC):
"""Provide a tabl... | 122 | 3,309 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/csv_table.py | .py | # Copyright (c) 2025 Microsoft Corporation.
# Licensed under the MIT Licenses
"""A CSV-based implementation of the Table abstraction for streaming row access."""
from __future__ import annotations
import csv
import inspect
import os
import shutil
import sys
import tempfile
from pathlib import Path
from typing import... | 207 | 7,209 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/parquet_table.py | .py | # Copyright (C) 2025 Microsoft
# Licensed under the MIT License
"""A Parquet-based implementation of the Table abstraction with simulated streaming."""
from __future__ import annotations
import inspect
from io import BytesIO
from typing import TYPE_CHECKING, Any, cast
import pandas as pd
from graphrag_storage.tabl... | 151 | 5,298 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Table provider module for GraphRAG storage."""
from .table import Table
from .table_provider import TableProvider
__all__ = ["Table", "TableProvider"]
| 10 | 234 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/cosmos_table.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Cosmos DB implementation of the Table abstraction for streaming row access."""
from __future__ import annotations
import inspect
import logging
from typing import TYPE_CHECKING, Any
from azure.cosmos.exceptions import CosmosResourceNotF... | 192 | 6,430 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/cosmos_table_provider.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Cosmos DB native table provider implementation.
Stores each DataFrame row as a Cosmos document, eliminating the
parquet serialization round-trip used by ParquetTableProvider.
Container schema
----------------
Partition key : /namespace
D... | 510 | 18,685 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/csv_table_provider.py | .py | # Copyright (c) 2025 Microsoft Corporation.
# Licensed under the MIT License
"""CSV-based table provider implementation."""
import logging
import re
from io import StringIO
import pandas as pd
from graphrag_storage.file_storage import FileStorage
from graphrag_storage.storage import Storage
from graphrag_storage.ta... | 151 | 5,059 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/parquet_table_provider.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Parquet-based table provider implementation."""
import logging
import re
from io import BytesIO
import pandas as pd
from graphrag_storage.storage import Storage
from graphrag_storage.tables.parquet_table import ParquetTable
from graphra... | 145 | 4,743 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/table_type.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Builtin table storage implementation types."""
from enum import StrEnum
class TableType(StrEnum):
"""Enum for table storage types."""
Parquet = "parquet"
CSV = "csv"
CosmosDB = "cosmosdb"
| 16 | 290 |
graphrag | packages/graphrag-storage/graphrag_storage/tables/table_provider_config.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Storage configuration model."""
from pydantic import BaseModel, ConfigDict, Field
from graphrag_storage.tables.table_type import TableType
class TableProviderConfig(BaseModel):
"""The default configuration section for table provide... | 36 | 1,081 |
graphrag | packages/graphrag-vectors/graphrag_vectors/types.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Common types for vector stores."""
from collections.abc import Callable
TextEmbedder = Callable[[str], list[float]]
| 9 | 199 |
graphrag | packages/graphrag-vectors/graphrag_vectors/azure_ai_search.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A package containing the Azure AI Search vector store implementation."""
from typing import Any
from azure.core.credentials import AzureKeyCredential
from azure.identity import DefaultAzureCredential
from azure.search.documents import S... | 374 | 13,179 |
graphrag | packages/graphrag-vectors/graphrag_vectors/index_schema.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Parameterization settings for the default configuration."""
import re
from pydantic import BaseModel, Field, model_validator
DEFAULT_VECTOR_SIZE: int = 3072
VALID_IDENTIFIER_REGEX = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
def is_vali... | 62 | 1,630 |
graphrag | packages/graphrag-vectors/graphrag_vectors/vector_store_config.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Parameterization settings for the default configuration."""
from pydantic import BaseModel, ConfigDict, Field
from graphrag_vectors.index_schema import DEFAULT_VECTOR_SIZE, IndexSchema
from graphrag_vectors.vector_store_type import Vecto... | 59 | 1,754 |
graphrag | packages/graphrag-vectors/graphrag_vectors/cosmosdb.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A package containing the CosmosDB vector store implementation."""
from typing import Any
from azure.cosmos import ContainerProxy, CosmosClient, DatabaseProxy
from azure.cosmos.exceptions import CosmosHttpResponseError
from azure.cosmos.p... | 422 | 15,763 |
graphrag | packages/graphrag-vectors/graphrag_vectors/vector_store_factory.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Factory functions for creating a vector store."""
from __future__ import annotations
from typing import TYPE_CHECKING
from graphrag_common.factory import Factory, ServiceScope
from graphrag_vectors.vector_store import VectorStore
from ... | 100 | 3,447 |
graphrag | packages/graphrag-vectors/graphrag_vectors/lancedb.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""The LanceDB vector storage implementation package."""
from typing import Any
import lancedb
import numpy as np
import pyarrow as pa
from graphrag_vectors.filtering import (
AndExpr,
Condition,
FilterExpr,
NotExpr,
Op... | 282 | 10,555 |
graphrag | packages/graphrag-vectors/graphrag_vectors/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""GraphRAG vector store implementations."""
from graphrag_vectors.filtering import (
AndExpr,
Condition,
F,
FilterExpr,
NotExpr,
Operator,
OrExpr,
)
from graphrag_vectors.index_schema import IndexSchema
from grap... | 53 | 1,237 |
graphrag | packages/graphrag-vectors/graphrag_vectors/timestamp.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Timestamp explosion for vector store indexing.
Converts an ISO 8601 timestamp string into a set of filterable component
fields, enabling temporal queries like "find documents from a Monday" or
"find documents from Q3 2024" using the stand... | 96 | 2,875 |
graphrag | packages/graphrag-vectors/graphrag_vectors/vector_store.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Base classes for vector stores."""
from abc import ABC, abstractmethod
from collections.abc import Callable
from dataclasses import dataclass, field
from datetime import datetime, timezone
from typing import Any
from graphrag_vectors.fil... | 217 | 7,058 |
graphrag | packages/graphrag-vectors/graphrag_vectors/filtering.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Generic filter expressions for vector store queries.
This module provides Pydantic-based filter expressions that can be:
1. Built programmatically using the F builder (for humans)
2. Generated as JSON by an LLM (structured output)
3. Seri... | 387 | 12,149 |
graphrag | packages/graphrag-vectors/graphrag_vectors/vector_store_type.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Vector store type enum."""
from enum import StrEnum
class VectorStoreType(StrEnum):
"""The supported vector store types."""
LanceDB = "lancedb"
AzureAISearch = "azure_ai_search"
CosmosDB = "cosmosdb"
| 15 | 301 |
graphrag | packages/graphrag/graphrag/__main__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""The GraphRAG package."""
from graphrag.cli.main import app
app(prog_name="graphrag")
| 9 | 168 |
graphrag | packages/graphrag/graphrag/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""The GraphRAG package."""
| 5 | 106 |
graphrag | packages/graphrag/graphrag/tokenizer/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""GraphRAG tokenizer."""
| 5 | 104 |
graphrag | packages/graphrag/graphrag/tokenizer/get_tokenizer.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Get Tokenizer."""
from graphrag_llm.config import ModelConfig, TokenizerConfig, TokenizerType
from graphrag_llm.tokenizer import Tokenizer, create_tokenizer
from graphrag.config.defaults import ENCODING_MODEL
def get_tokenizer(
mod... | 49 | 1,610 |
graphrag | packages/graphrag/graphrag/graphs/edge_weights.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Edge weight calculation utilities (PMI, RRF)."""
import numpy as np
import pandas as pd
def calculate_pmi_edge_weights(
nodes_df: pd.DataFrame,
edges_df: pd.DataFrame,
node_name_col: str = "title",
node_freq_col: str = "... | 102 | 3,199 |
graphrag | packages/graphrag/graphrag/graphs/modularity.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Compute graph modularity directly from an edge list DataFrame."""
import logging
import math
from collections import defaultdict
import pandas as pd
from graphrag.config.enums import ModularityMetric
from graphrag.graphs.connected_compo... | 296 | 9,874 |
graphrag | packages/graphrag/graphrag/graphs/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Graph utilities that operate on DataFrames instead of NetworkX objects."""
| 5 | 156 |
graphrag | packages/graphrag/graphrag/graphs/connected_components.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Find connected components and the largest connected component from an edge list DataFrame."""
import pandas as pd
def connected_components(
relationships: pd.DataFrame,
source_column: str = "source",
target_column: str = "ta... | 94 | 2,633 |
graphrag | packages/graphrag/graphrag/graphs/stable_lcc.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Produce a stable largest connected component from a relationships DataFrame.
"Stable" means the same input edge list always produces the same output,
regardless of the original row order. This is achieved by:
1. Filtering to the largest... | 76 | 2,528 |
graphrag | packages/graphrag/graphrag/graphs/compute_degree.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Compute node degree directly from a relationships DataFrame."""
import pandas as pd
def compute_degree(
relationships: pd.DataFrame,
source_column: str = "source",
target_column: str = "target",
) -> pd.DataFrame:
"""Com... | 44 | 1,427 |
graphrag | packages/graphrag/graphrag/graphs/hierarchical_leiden.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Hierarchical Leiden clustering on edge lists."""
from typing import Any
import graspologic_native as gn
def hierarchical_leiden(
edges: list[tuple[str, str, float]],
max_cluster_size: int = 10,
random_seed: int | None = 0xD... | 55 | 1,525 |
graphrag | packages/graphrag/graphrag/query/indexer_adapters.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Indexing-Engine to Query Read Adapters.
The parts of these functions that do type adaptation, renaming, collating, etc. should eventually go away.
Ideally this is just a straight read-through into the object model.
"""
import logging
from... | 226 | 7,574 |
graphrag | packages/graphrag/graphrag/query/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""The query engine package root."""
| 5 | 115 |
graphrag | packages/graphrag/graphrag/query/factory.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Query Factory methods to support CLI."""
from graphrag_llm.completion import create_completion
from graphrag_llm.embedding import create_embedding
from graphrag_vectors import VectorStore
from graphrag.callbacks.query_callbacks import Qu... | 276 | 10,291 |
graphrag | packages/graphrag/graphrag/query/context_builder/rate_prompt.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Global search with dynamic community selection prompt."""
RATE_QUERY = """
---Role---
You are a helpful assistant responsible for deciding whether the provided information is useful in answering a given question, even if it is only partia... | 24 | 868 |
graphrag | packages/graphrag/graphrag/query/context_builder/local_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Local Context Builder."""
from collections import defaultdict
from typing import Any, cast
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
from graphrag.data_model.covariate import Covariate
from graphrag.data_model.ent... | 358 | 13,290 |
graphrag | packages/graphrag/graphrag/query/context_builder/community_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Community Context."""
import logging
import random
from typing import Any, cast
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
from graphrag.data_model.community_report import CommunityReport
from graphrag.data_model.e... | 265 | 9,385 |
graphrag | packages/graphrag/graphrag/query/context_builder/source_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Context Build utility methods."""
import random
from typing import Any, cast
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
from graphrag.data_model.relationship import Relationship
from graphrag.data_model.text_unit i... | 101 | 3,292 |
graphrag | packages/graphrag/graphrag/query/context_builder/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Functions to build context for system prompt to generate responses for a user query."""
| 5 | 169 |
graphrag | packages/graphrag/graphrag/query/context_builder/builders.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Base classes for global and local context builders."""
from abc import ABC, abstractmethod
from dataclasses import dataclass
import pandas as pd
from graphrag.query.context_builder.conversation_history import (
ConversationHistory,
... | 76 | 1,915 |
graphrag | packages/graphrag/graphrag/query/context_builder/entity_extraction.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Orchestration Context Builders."""
from enum import Enum
from typing import TYPE_CHECKING
from graphrag_vectors import VectorStore
from graphrag.data_model.entity import Entity
from graphrag.data_model.relationship import Relationship
f... | 126 | 4,385 |
graphrag | packages/graphrag/graphrag/query/context_builder/dynamic_community_selection.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Algorithm to dynamically select relevant communities with respect to a query."""
import asyncio
import logging
from collections import Counter
from copy import deepcopy
from time import time
from typing import TYPE_CHECKING, Any
from gra... | 177 | 6,830 |
graphrag | packages/graphrag/graphrag/query/context_builder/conversation_history.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Classes for storing and managing conversation history."""
from dataclasses import dataclass
from enum import Enum
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
from graphrag.tokenizer.get_tokenizer import get_tokenize... | 227 | 7,750 |
graphrag | packages/graphrag/graphrag/query/context_builder/rate_relevancy.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Algorithm to rate the relevancy between a query and description text."""
import asyncio
import logging
from contextlib import nullcontext
from typing import TYPE_CHECKING, Any
import numpy as np
from graphrag_llm.tokenizer import Tokeniz... | 87 | 3,126 |
graphrag | packages/graphrag/graphrag/query/llm/text_utils.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Text Utilities for LLM."""
import json
import logging
import re
from collections.abc import Iterable, Iterator
from itertools import islice
from typing import TypeVar
from graphrag_llm.tokenizer import Tokenizer
from json_repair import r... | 109 | 3,262 |
graphrag | packages/graphrag/graphrag/query/llm/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Orchestration LLM utilities."""
| 5 | 113 |
graphrag | packages/graphrag/graphrag/query/structured_search/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Structured Search package."""
| 5 | 111 |
graphrag | packages/graphrag/graphrag/query/structured_search/base.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Base classes for search algos."""
from abc import ABC, abstractmethod
from collections.abc import AsyncGenerator
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Generic, TypeVar
import pandas as pd
from graphrag_... | 94 | 2,775 |
graphrag | packages/graphrag/graphrag/query/structured_search/global_search/community_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Contains algorithms to build context data for global search prompt."""
from typing import Any
from graphrag_llm.tokenizer import Tokenizer
from graphrag.data_model.community import Community
from graphrag.data_model.community_report imp... | 148 | 5,860 |
graphrag | packages/graphrag/graphrag/query/structured_search/global_search/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""GlobalSearch module."""
| 5 | 105 |
graphrag | packages/graphrag/graphrag/query/structured_search/global_search/search.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""The GlobalSearch Implementation."""
import asyncio
import json
import logging
import time
from collections.abc import AsyncGenerator, AsyncIterator
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
import pandas as ... | 522 | 20,309 |
graphrag | packages/graphrag/graphrag/query/structured_search/basic_search/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""The BasicSearch package."""
| 5 | 109 |
graphrag | packages/graphrag/graphrag/query/structured_search/basic_search/search.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""BasicSearch implementation."""
import logging
import time
from collections.abc import AsyncGenerator, AsyncIterator
from typing import TYPE_CHECKING, Any
from graphrag_llm.tokenizer import Tokenizer
from graphrag_llm.utils import Complet... | 183 | 6,777 |
graphrag | packages/graphrag/graphrag/query/structured_search/basic_search/basic_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Basic Context Builder implementation."""
import logging
from typing import TYPE_CHECKING, cast
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
from graphrag_vectors import VectorStore
from graphrag.data_model.text_unit ... | 110 | 3,772 |
graphrag | packages/graphrag/graphrag/query/structured_search/local_search/mixed_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Algorithms to build context data for local search prompt."""
import logging
from copy import deepcopy
from typing import TYPE_CHECKING, Any
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
from graphrag_vectors import Vect... | 494 | 21,320 |
graphrag | packages/graphrag/graphrag/query/structured_search/local_search/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""The LocalSearch package."""
| 5 | 109 |
graphrag | packages/graphrag/graphrag/query/structured_search/local_search/search.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""LocalSearch implementation."""
import logging
import time
from collections.abc import AsyncGenerator, AsyncIterator
from typing import TYPE_CHECKING, Any
from graphrag_llm.tokenizer import Tokenizer
from graphrag_llm.utils import Complet... | 184 | 6,923 |
graphrag | packages/graphrag/graphrag/query/structured_search/drift_search/primer.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Primer for DRIFT search."""
import logging
import secrets
import time
from typing import TYPE_CHECKING
import numpy as np
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
from pydantic import BaseModel, Field
from tqdm.as... | 230 | 8,523 |
graphrag | packages/graphrag/graphrag/query/structured_search/drift_search/state.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Manage the state of the DRIFT query, including a graph of actions."""
import logging
import random
from collections.abc import Callable
from typing import Any
import networkx as nx
from graphrag.query.structured_search.drift_search.acti... | 151 | 5,320 |
graphrag | packages/graphrag/graphrag/query/structured_search/drift_search/drift_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""DRIFT Context Builder implementation."""
import logging
from dataclasses import asdict
from typing import TYPE_CHECKING, Any
import numpy as np
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
from graphrag_vectors import... | 230 | 8,076 |
graphrag | packages/graphrag/graphrag/query/structured_search/drift_search/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""DriftSearch module."""
| 5 | 104 |
graphrag | packages/graphrag/graphrag/query/structured_search/drift_search/action.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""DRIFT Search Query State."""
import json
import logging
from typing import Any
from graphrag.query.llm.text_utils import try_parse_json_object
logger = logging.getLogger(__name__)
class DriftAction:
"""
Represent an action con... | 246 | 7,901 |
graphrag | packages/graphrag/graphrag/query/structured_search/drift_search/search.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""DRIFT Search implementation."""
import logging
import time
from collections.abc import AsyncGenerator, AsyncIterator
from typing import TYPE_CHECKING, Any
from graphrag_llm.tokenizer import Tokenizer
from graphrag_llm.utils import (
... | 465 | 17,105 |
graphrag | packages/graphrag/graphrag/query/input/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""GraphRAG Orchestration Inputs."""
| 5 | 115 |
graphrag | packages/graphrag/graphrag/query/input/loaders/utils.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Data load utils."""
from collections.abc import Mapping
from typing import Any
import numpy as np
def _get_value(
data: Mapping[str, Any], column_name: str | None, required: bool = True
) -> Any:
"""
Retrieve a column value... | 188 | 6,165 |
graphrag | packages/graphrag/graphrag/query/input/loaders/dfs.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Load data from dataframes into collections of data objects."""
import pandas as pd
from graphrag.data_model.community import Community
from graphrag.data_model.community_report import CommunityReport
from graphrag.data_model.covariate im... | 258 | 9,160 |
graphrag | packages/graphrag/graphrag/query/input/loaders/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""GraphRAG Orchestartion Input Loaders."""
| 5 | 122 |
graphrag | packages/graphrag/graphrag/query/input/retrieval/text_units.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Util functions to retrieve text units from a collection."""
from typing import Any, cast
import pandas as pd
from graphrag.data_model.entity import Entity
from graphrag.data_model.text_unit import TextUnit
def get_candidate_text_units... | 54 | 1,727 |
graphrag | packages/graphrag/graphrag/query/input/retrieval/relationships.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Util functions to retrieve relationships from a collection."""
from typing import Any, cast
import pandas as pd
from graphrag.data_model.entity import Entity
from graphrag.data_model.relationship import Relationship
def get_in_network... | 140 | 5,125 |
graphrag | packages/graphrag/graphrag/query/input/retrieval/covariates.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Util functions to retrieve covariates from a collection."""
from typing import Any, cast
import pandas as pd
from graphrag.data_model.covariate import Covariate
from graphrag.data_model.entity import Entity
def get_candidate_covariate... | 54 | 1,747 |
graphrag | packages/graphrag/graphrag/query/input/retrieval/community_reports.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Util functions to retrieve community reports from a collection."""
from typing import Any, cast
import pandas as pd
from graphrag.data_model.community_report import CommunityReport
from graphrag.data_model.entity import Entity
def get... | 76 | 2,504 |
graphrag | packages/graphrag/graphrag/query/input/retrieval/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""GraphRAG Orchestration Input Retrieval."""
| 5 | 124 |
graphrag | packages/graphrag/graphrag/query/input/retrieval/entities.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Util functions to get entities from a collection."""
import uuid
from collections.abc import Iterable
from typing import Any, cast
import pandas as pd
from graphrag.data_model.entity import Entity
def get_entity_by_id(entities: dict[s... | 103 | 3,083 |
graphrag | packages/graphrag/graphrag/query/question_gen/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Question Generation Module."""
| 5 | 112 |
graphrag | packages/graphrag/graphrag/query/question_gen/local_gen.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Local question generation."""
import logging
import time
from typing import TYPE_CHECKING, Any, cast
from graphrag_llm.tokenizer import Tokenizer
from graphrag_llm.utils import CompletionMessagesBuilder
from graphrag.callbacks.llm_callb... | 238 | 8,342 |
graphrag | packages/graphrag/graphrag/query/question_gen/base.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Base classes for generating questions based on previously asked questions and most recent context data."""
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
from graphrag_llm.toke... | 68 | 1,839 |
graphrag | packages/graphrag/graphrag/index/validate_config.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing validate_config_names definition."""
import asyncio
import logging
import sys
from typing import TYPE_CHECKING
from graphrag_llm.completion import create_completion
from graphrag_llm.embedding import create_embedding
... | 74 | 2,649 |
graphrag | packages/graphrag/graphrag/index/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""The indexing engine package root."""
| 5 | 118 |
graphrag | packages/graphrag/graphrag/index/operations/finalize_relationships.py | .py | # Copyright (C) 2026 Microsoft
# Licensed under the MIT License
"""Stream-finalize relationship rows into an output Table."""
from typing import Any
from uuid import uuid4
from graphrag_storage.tables.table import Table
from graphrag.data_model.schemas import RELATIONSHIPS_FINAL_COLUMNS
async def finalize_relatio... | 56 | 1,755 |
graphrag | packages/graphrag/graphrag/index/operations/cluster_graph.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing cluster_graph method definition."""
import logging
from collections import defaultdict
import pandas as pd
from graphrag.graphs.hierarchical_leiden import hierarchical_leiden
from graphrag.graphs.stable_lcc import st... | 100 | 3,146 |
graphrag | packages/graphrag/graphrag/index/operations/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Reusable data frame operations."""
| 5 | 116 |
graphrag | packages/graphrag/graphrag/index/operations/finalize_entities.py | .py | # Copyright (C) 2026 Microsoft
# Licensed under the MIT License
"""Stream-finalize entity rows into an output Table."""
from typing import Any
from uuid import uuid4
from graphrag_storage.tables.table import Table
from graphrag.data_model.schemas import ENTITIES_FINAL_COLUMNS
async def finalize_entities(
enti... | 57 | 1,704 |
graphrag | packages/graphrag/graphrag/index/operations/finalize_community_reports.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""All the steps to transform final entities."""
import pandas as pd
from graphrag.data_model.schemas import COMMUNITY_REPORTS_FINAL_COLUMNS
from graphrag.index.utils.hashing import gen_sha512_hash
def finalize_community_reports(
repo... | 34 | 1,051 |
graphrag | packages/graphrag/graphrag/index/operations/snapshot_graphml.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing snapshot_graphml method definition."""
import networkx as nx
import pandas as pd
from graphrag_storage import Storage
async def snapshot_graphml(
edges: pd.DataFrame,
name: str,
storage: Storage,
) -> Non... | 20 | 562 |
graphrag | packages/graphrag/graphrag/index/operations/prune_graph.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Graph pruning."""
import numpy as np
import pandas as pd
import graphrag.data_model.schemas as schemas
from graphrag.graphs.compute_degree import compute_degree
from graphrag.graphs.connected_components import largest_connected_component... | 116 | 4,567 |
graphrag | packages/graphrag/graphrag/index/operations/compute_edge_combined_degree.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing compute_edge_combined_degree method definition."""
from typing import cast
import pandas as pd
def compute_edge_combined_degree(
edge_df: pd.DataFrame,
node_degree_df: pd.DataFrame,
node_name_column: str... | 44 | 1,325 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/explode_communities.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Explode a list of communities into nodes for filtering."""
import pandas as pd
from graphrag.data_model.schemas import (
COMMUNITY_ID,
)
def explode_communities(
communities: pd.DataFrame, entities: pd.DataFrame
) -> pd.DataFra... | 24 | 665 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/utils.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing community report generation utilities."""
import pandas as pd
import graphrag.data_model.schemas as schemas
def get_levels(
df: pd.DataFrame, level_column: str = schemas.COMMUNITY_LEVEL
) -> list[int]:
"""Ge... | 18 | 499 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/community_reports_extractor.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing 'CommunityReportsResult' and 'CommunityReportsExtractor' models."""
import logging
import traceback
from dataclasses import dataclass
from typing import TYPE_CHECKING
from pydantic import BaseModel, Field
from graphr... | 103 | 3,315 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/summarize_communities.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing summarize_communities method definition."""
import logging
from collections.abc import Callable
from typing import TYPE_CHECKING
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
import graphrag.data_m... | 165 | 5,112 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Community summarization modules."""
| 5 | 117 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/typing.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing 'Finding' and 'CommunityReport' models."""
from collections.abc import Awaitable, Callable
from typing import TYPE_CHECKING, Any
from typing_extensions import TypedDict
if TYPE_CHECKING:
from graphrag_llm.complet... | 50 | 964 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/build_mixed_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing build_mixed_context method definition."""
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
import graphrag.data_model.schemas as schemas
from graphrag.index.operations.summarize_communities.graph_conte... | 75 | 2,963 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/text_unit_context/sort_context.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Sort local context by total degree of associated nodes in descending order."""
import logging
import pandas as pd
from graphrag_llm.tokenizer import Tokenizer
import graphrag.data_model.schemas as schemas
logger = logging.getLogger(__n... | 86 | 2,804 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/text_unit_context/__init__.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Package of context builders for text unit-based reports."""
| 5 | 141 |
graphrag | packages/graphrag/graphrag/index/operations/summarize_communities/text_unit_context/prep_text_units.py | .py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Prepare text units for community reports."""
import logging
import pandas as pd
import graphrag.data_model.schemas as schemas
logger = logging.getLogger(__name__)
def prep_text_units(
text_unit_df: pd.DataFrame,
node_df: pd.D... | 47 | 1,415 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.