Module postprocessor (0.4.0)

API documentation for postprocessor module.

Classes

AlloyDBRerank

AlloyDBRerank(engine: llama_index_alloydb_pg.engine.AlloyDBEngine, model_id: str, top_n: int = 2, *, callback_manager: llama_index.core.callbacks.base.CallbackManager = <factory>)

Reranks nodes with AlloyDB AI's google_ml.rank() function.

The ranking runs inside the database through AlloyDB's Vertex AI integration. As listed in https://cloud.google.com/alloydb/docs/ai/rank-rerank-search-results-rag, it needs the google_ml_integration extension 1.5.2 or later, the google_ml_integration.enable_model_support and google_ml_integration.enable_ai_query_engine flags on, the Discovery Engine API enabled and roles/discoveryengine.viewer for the AlloyDB service agent. Nodes with no text (an ImageNode) or only whitespace or format characters are left out. Database errors are raised unchanged. Async apostprocess_nodes needs llama-index-core 0.12.32 or later.

Modules Functions

_has_text

_has_text(node: llama_index.core.schema.NodeWithScore) -> bool

Whether the text has a character other than whitespace or format (Cf).

_to_ranked_nodes

_to_ranked_nodes(
    nodes: typing.Sequence[llama_index.core.schema.NodeWithScore],
    rows: typing.Sequence[sqlalchemy.engine.row.RowMapping],
) -> typing.List[llama_index.core.schema.NodeWithScore]

Map 1-based (index, score) rows to new nodes, highest score first.