# Ecommerce Search Ranking Regression (`merciful_goldenlarch/ecommerce-search-ranking-regression`) Actor

Compare before and after ecommerce search rankings against relevance judgments. Use one CSV to calculate nDCG and find which product queries lost relevance.

- **URL**: https://apify.com/merciful_goldenlarch/ecommerce-search-ranking-regression.md
- **Developed by:** [Toolshed](https://apify.com/merciful_goldenlarch) (community)
- **Categories:** E-commerce, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 query results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Ecommerce Search Ranking Regression

Find which ecommerce search queries lost relevance after a ranking change. Supply before and after product ranks and existing relevance judgments to calculate per-query nDCG. The [Toolshed search ranking guide](https://toolshed-guides.vercel.app/ranking/) shows the CSV header and sample output.

Click **Start** to compare two prefilled product queries. **Q113734** drops about 0.053 points, while **Q10108** gains about 0.136 points. The sample uses saved Shopping Lab rankings and judgments from the [Amazon Shopping Queries Dataset](https://github.com/amazon-science/esci-data/tree/7916cdf6ab75a462e77f20ab40428a10923998d5). The included ESCI license and notice apply to the example data.

For your own comparison, put one judged product per row in a spreadsheet with these five columns:

```text
query_id,product_id,label,before_rank,after_rank
```

Use `E` for exact, `S` for substitute, `C` for complement and `I` for irrelevant. For each query, give every product a unique rank in both versions, starting at 1 with no gaps. Export the sheet as CSV, replace the prefilled CSV with your table and click **Start**. Open **Dataset** to see the biggest declines first, with before and after scores and the first result's relevance label.

The JSON API remains available through the alternative JSON field. Clear the CSV field first and send `schema_version` 1, optional `k`, and `queries` with the `query_id`, `judgments`, `before` and `after` fields. The judgments contain `product_id` and `label`. The ranking arrays list the same IDs in rank order.

NDCG measures how high relevant items appear in the ranked list. The cutoff defaults to 10, and the four labels carry weights of 1, 0.1, 0.01 and 0 respectively. Each comparison uses one shared candidate set. Inputs are limited to 2 MiB, 5,000 queries and 200 judged products per query. The Actor uses the supplied data and requires no search API or account credentials.

### Read the findings

The default result view shows a readable finding, the affected item, what the evidence means and what to do next. Switch to **Evidence and source fields** for the underlying records. Download **REVIEW.csv** to work in a spreadsheet, or **REVIEW.html** for a plain report. Suggested actions are checks for you to perform; the Actor has not executed them. Existing API evidence fields are retained alongside the reading layer.

If the run budget cannot deliver every result row, the run fails rather than silently returning a complete-looking partial dataset. Check **Dataset delivery status** in Output, reduce the input or increase the run budget, and start a new run. A successful dataset-delivery check confirms storage, not source accuracy or full workflow compatibility.

Query IDs may be the actual search text, including spaces and non-English characters, up to 128 printable characters. Product IDs keep their documented restricted format; control characters and duplicate query IDs are rejected.

# Actor input Schema

## `rankingsCsv` (type: `string`):

Keep the example or paste a spreadsheet exported as CSV with query_id, product_id, label, before_rank and after_rank.

## `rankingsJson` (type: `string`):

For the JSON API format, clear the CSV box and paste your JSON here.

## Actor input object example

```json
{
  "rankingsCsv": "query_id,product_id,label,before_rank,after_rank\nQ113734,B001H1K0PG,I,5,5\nQ113734,B0027P9YMQ,I,7,7\nQ113734,B003AYX3UC,I,2,3\nQ113734,B004U7L94K,I,8,6\nQ113734,B00BFW8XJC,I,6,4\nQ113734,B00OJOY4J6,E,9,9\nQ113734,B01D5I8FO6,I,3,2\nQ113734,B07CT6133T,E,1,1\nQ113734,B07GPCLDSQ,S,10,10\nQ113734,B07RZV2VTJ,E,4,8\nQ10108,B0149HDN3K,E,5,6\nQ10108,B0155G6JYO,E,4,5\nQ10108,B01AS12CEW,E,3,2\nQ10108,B077YDZ725,I,7,8\nQ10108,B07GQNTWKJ,S,8,9\nQ10108,B07H429RS6,E,9,7\nQ10108,B07JVMJ3F5,E,2,1\nQ10108,B07KB8TZ6Z,S,6,4\nQ10108,B07RQQ523T,S,1,3\n"
}
```

# Actor output Schema

## `dataset` (type: `string`):

No description

## `report` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `reviewCsv` (type: `string`):

No description

## `reviewHtml` (type: `string`):

No description

## `deliveryStatus` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "rankingsCsv": `query_id,product_id,label,before_rank,after_rank
Q113734,B001H1K0PG,I,5,5
Q113734,B0027P9YMQ,I,7,7
Q113734,B003AYX3UC,I,2,3
Q113734,B004U7L94K,I,8,6
Q113734,B00BFW8XJC,I,6,4
Q113734,B00OJOY4J6,E,9,9
Q113734,B01D5I8FO6,I,3,2
Q113734,B07CT6133T,E,1,1
Q113734,B07GPCLDSQ,S,10,10
Q113734,B07RZV2VTJ,E,4,8
Q10108,B0149HDN3K,E,5,6
Q10108,B0155G6JYO,E,4,5
Q10108,B01AS12CEW,E,3,2
Q10108,B077YDZ725,I,7,8
Q10108,B07GQNTWKJ,S,8,9
Q10108,B07H429RS6,E,9,7
Q10108,B07JVMJ3F5,E,2,1
Q10108,B07KB8TZ6Z,S,6,4
Q10108,B07RQQ523T,S,1,3`
};

// Run the Actor and wait for it to finish
const run = await client.actor("merciful_goldenlarch/ecommerce-search-ranking-regression").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "rankingsCsv": """query_id,product_id,label,before_rank,after_rank
Q113734,B001H1K0PG,I,5,5
Q113734,B0027P9YMQ,I,7,7
Q113734,B003AYX3UC,I,2,3
Q113734,B004U7L94K,I,8,6
Q113734,B00BFW8XJC,I,6,4
Q113734,B00OJOY4J6,E,9,9
Q113734,B01D5I8FO6,I,3,2
Q113734,B07CT6133T,E,1,1
Q113734,B07GPCLDSQ,S,10,10
Q113734,B07RZV2VTJ,E,4,8
Q10108,B0149HDN3K,E,5,6
Q10108,B0155G6JYO,E,4,5
Q10108,B01AS12CEW,E,3,2
Q10108,B077YDZ725,I,7,8
Q10108,B07GQNTWKJ,S,8,9
Q10108,B07H429RS6,E,9,7
Q10108,B07JVMJ3F5,E,2,1
Q10108,B07KB8TZ6Z,S,6,4
Q10108,B07RQQ523T,S,1,3
""" }

# Run the Actor and wait for it to finish
run = client.actor("merciful_goldenlarch/ecommerce-search-ranking-regression").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "rankingsCsv": "query_id,product_id,label,before_rank,after_rank\\nQ113734,B001H1K0PG,I,5,5\\nQ113734,B0027P9YMQ,I,7,7\\nQ113734,B003AYX3UC,I,2,3\\nQ113734,B004U7L94K,I,8,6\\nQ113734,B00BFW8XJC,I,6,4\\nQ113734,B00OJOY4J6,E,9,9\\nQ113734,B01D5I8FO6,I,3,2\\nQ113734,B07CT6133T,E,1,1\\nQ113734,B07GPCLDSQ,S,10,10\\nQ113734,B07RZV2VTJ,E,4,8\\nQ10108,B0149HDN3K,E,5,6\\nQ10108,B0155G6JYO,E,4,5\\nQ10108,B01AS12CEW,E,3,2\\nQ10108,B077YDZ725,I,7,8\\nQ10108,B07GQNTWKJ,S,8,9\\nQ10108,B07H429RS6,E,9,7\\nQ10108,B07JVMJ3F5,E,2,1\\nQ10108,B07KB8TZ6Z,S,6,4\\nQ10108,B07RQQ523T,S,1,3\\n"
}' |
apify call merciful_goldenlarch/ecommerce-search-ranking-regression --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,merciful_goldenlarch/ecommerce-search-ranking-regression"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Q0RMg9v1cagxmEcEm/builds/uREdnyFvHd1wS4IJd/openapi.json
