Skip to content

Compressor

A base class for compressing prompt components in Gen AI applications.

Authors

Dimitrij Ray (dimitrij.ray@gdplabs.id)

References

NONE

BaseCompressor

Bases: Component, ABC

An abstract base class for compressing prompt components in Gen AI applications.

A prompt may consist of multiple components, such as an instruction, a context, and a query. A compressor may be used to compress any number of these components.

compress(context, query, instruction=None, options=None) abstractmethod async

Compresses the given context string based on the query and optional instruction.

This method must be implemented by subclasses to define the specific compression logic.

Parameters:

Name Type Description Default
context str

The already-packed context string to be compressed.

required
query str

The query related to the context, used for query-dependent compression.

required
instruction str | None

An optional instruction to be considered during compression. Defaults to None.

None
options dict[str, Any] | None

Additional options for fine-tuning the compression process. The specific supported options depend on the implementing class. Defaults to None.

None

Returns:

Name Type Description
str str

The compressed context string.

Raises:

Type Description
NotImplementedError

This method must be implemented by derived classes.