graphrag/graphrag/query/context_builder/builders.py
Julian Whiting d24e0bd3cc formatting
2024-10-11 16:27:25 -04:00

48 lines
1.2 KiB
Python

# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Base classes for global and local context builders."""
from abc import ABC, abstractmethod
import pandas as pd
from graphrag.query.context_builder.conversation_history import (
ConversationHistory,
)
class GlobalContextBuilder(ABC):
"""Base class for global-search context builders."""
@abstractmethod
def build_context(
self, conversation_history: ConversationHistory | None = None, **kwargs
) -> tuple[str | list[str], dict[str, pd.DataFrame]]:
"""Build the context for the global search mode."""
class LocalContextBuilder(ABC):
"""Base class for local-search context builders."""
@abstractmethod
def build_context(
self,
query: str,
conversation_history: ConversationHistory | None = None,
**kwargs,
) -> tuple[str | list[str], dict[str, pd.DataFrame]]:
"""Build the context for the local search mode."""
class DRIFTContextBuilder(ABC):
"""Base class for DRIFT-search context builders."""
@abstractmethod
def build_context(
self,
query: str,
**kwargs,
) -> pd.DataFrame:
"""Build the context for the primer search actions."""