Retrieval

class interact.retrieval.EncoderType(*args, **kwargs)

Bases: Protocol

A protocol for an encoder function.

class interact.retrieval.Record

Bases: BaseModel

A class representing a record with semantic fields.

class interact.retrieval.SimpleRecord(text, *, metadata, **data)

Bases: Record

Parameters:
  • text (str)

  • metadata (dict)

metadata: dict
text: str
class interact.retrieval.VectorDB(*args, **kwargs)

Bases: Protocol[T]

A protocol for a vector database.

add_records(dataset)
Parameters:

dataset (list[T])

Return type:

None

collect_records(string_ids)

Gathers the records corresponding to the given string IDs.

Parameters:

string_ids (list[int]) – A list of string IDs.

Returns:

A list of Record objects corresponding to the given string IDs. If a record appears multiple times in string_ids, later occurrences will be ignored.

Return type:

list[Record]

encoder: EncoderType
query(query, k)
Parameters:
Return type:

list[T]

refresh_records(dataset)

Refreshes the records in the dataset and updates the internal data stores.

Parameters:

dataset (list[Record]) – A list of Record objects representing the dataset.

Returns:

A dictionary mapping string IDs to the strings in the dataset.

Return type:

dict[int, str]

class interact.retrieval.faiss.FaissIndexDB(index, dataset, encoder, train=False)

Bases: VectorDB[T]

Parameters:
  • index (Index | tuple[int, str])

  • dataset (Sequence[T])

  • encoder (EncoderType)

  • train (bool)

add_records(dataset, train=False)
Parameters:
  • dataset (Sequence[T])

  • train (bool)

Return type:

None

index_db: Index
query(query, k=5)
Parameters:
Return type:

list[T]