Skip to content

base

Base classes for augmentation steps.

Classes:

AugmentedBase

AugmentedBase(
    model_name: Optional[str] = None,
    db: DBBase | None = None,
    top_k: Optional[int] = None,
    api_key: str = '',
    api_params: dict[str, Any] | None = None,
    cache: Cache | None = None,
    logs: dict[str, Any] | None = None,
)

Bases: StepBase

Base class for all augmentation steps.

Methods:

  • apply

    Apply attached configuration to the step.

  • get_embedding

    Retrieve embeddings for the given texts.

  • process

    Run augmentation against the current pipeline content.

  • search

    Search for the most relevant documents.

Source code in src/rago/augmented/base.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def __init__(
    self,
    model_name: Optional[str] = None,
    db: DBBase | None = None,
    top_k: Optional[int] = None,
    api_key: str = '',
    api_params: dict[str, Any] | None = None,
    cache: Cache | None = None,
    logs: dict[str, Any] | None = None,
) -> None:
    super().__init__()
    self.api_key = api_key
    self.api_params = api_params or {}
    self.cache = cache
    self.logs = logs if logs is not None else {}
    self.db = db or FaissDB()
    self.top_k = top_k if top_k is not None else self.default_top_k
    self.model_name = (
        model_name if model_name is not None else self.default_model_name
    )
    self.model = None

    self._validate()
    self._load_optional_modules()
    self._setup()

apply

apply(parameters: Any) -> None

Apply attached configuration to the step.

Source code in src/rago/base.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def apply(self, parameters: Any) -> None:
    """Apply attached configuration to the step."""
    if parameters is None:
        return

    if _is_cache_backend(parameters):
        self.cache = parameters
        return

    if _is_vector_db(parameters):
        setattr(self, 'db', parameters)
        return

    if _is_text_splitter(parameters):
        setattr(self, 'splitter', parameters)
        return

    for key, value in config_to_dict(parameters).items():
        if key == 'cache':
            self.cache = value
        elif key == 'logs':
            self.logs = value if value is not None else {}
        else:
            setattr(self, key, value)

get_embedding

get_embedding(content: list[str]) -> EmbeddingType

Retrieve embeddings for the given texts.

Source code in src/rago/augmented/base.py
127
128
129
def get_embedding(self, content: list[str]) -> EmbeddingType:
    """Retrieve embeddings for the given texts."""
    raise Exception('Method not implemented.')

process

process(inp: Input) -> Output

Run augmentation against the current pipeline content.

Source code in src/rago/augmented/base.py
154
155
156
157
158
159
160
161
162
def process(self, inp: Input) -> Output:
    """Run augmentation against the current pipeline content."""
    query = str(inp.query)
    content = inp.get('content', inp.get('data', inp.get('source')))
    result = self.search(query, ensure_list(content), top_k=self.top_k)
    output = Output.from_input(inp)
    output.content = result
    output.data = result
    return output

search abstractmethod

search(
    query: str, documents: Any, top_k: int = 0
) -> list[str]

Search for the most relevant documents.

Source code in src/rago/augmented/base.py
131
132
133
@abstractmethod
def search(self, query: str, documents: Any, top_k: int = 0) -> list[str]:
    """Search for the most relevant documents."""