Skip to main content

LlamaIndex Postprocessor Integration: Google Rerank

Uses Google's Discovery Engine Ranking API to rerank search results based on query relevance.

Installation

pip install llama-index-postprocessor-google-rerank

Prerequisites

Usage

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.postprocessor.google_rerank import GoogleRerank

documents = SimpleDirectoryReader("./data/paul_graham/").load_data()
index = VectorStoreIndex.from_documents(documents=documents)

reranker = GoogleRerank(
    top_n=3,
    project_id="your-gcp-project-id",
    model="semantic-ranker-default-004",
)

query_engine = index.as_query_engine(
    similarity_top_k=10,
    node_postprocessors=[reranker],
)
response = query_engine.query("What did Sam Altman do in this essay?")
print(response)

Available Models

Model Context Window Notes
semantic-ranker-default-004 (default) 1024 tokens Latest, multilingual
semantic-ranker-default-003 512 tokens Multilingual
semantic-ranker-default-002 512 tokens English only

Configuration

Parameter Type Default Description
model str "semantic-ranker-default-004" Ranking model name
top_n int 2 Number of top results to return
project_id str None GCP project ID (falls back to GOOGLE_CLOUD_PROJECT env var, then ADC)
location str "global" GCP location for the ranking config
ranking_config str "default_ranking_config" Ranking config resource name
credentials Credentials None Optional Google auth credentials object

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_postprocessor_google_rerank-0.2.0.tar.gz.

File metadata

  • Download URL: llama_index_postprocessor_google_rerank-0.2.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_postprocessor_google_rerank-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b8308bd7cd04c3e1d8b1f609d765a708d7369ebedd478236f718fbc9545801d4
MD5 604b2cf46e34360f425d081383d612e4
BLAKE2b-256 5b0d4abaf447d96d90725429f832ee896b87b721af15233967c612f92e29a67c

See more details on using hashes here.

File details

Details for the file llama_index_postprocessor_google_rerank-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_postprocessor_google_rerank-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_postprocessor_google_rerank-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7c5ac45f9dd21ba58d9c704a63d2a64e539578ae4af28c9a07130714b86c7f2
MD5 0386d993184d25a873d17fa14c286d99
BLAKE2b-256 0c737a4eefdc3a63d49d02a96e70a36523d1b647623a7ef431294389eabd94cb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page