liveBook · Manning

AI-assisted ranking and filtering

As explained in Learn AI Data Engineering

AI ranking is the evaluation and ordering of candidate items by an artificial intelligence model according to specified criteria.

AI-assisted ranking and filtering evaluates candidate items against explicit criteria and returns an ordered or selected result. For URL discovery, a search step supplies candidates, then a model chooses the strongest product page instead of requiring a person to search and evaluate every result manually. section 11.4.2 section 10.4.3

A practical ranking pipeline separates deterministic preparation from model judgment:

  • Collect candidate search results programmatically, preserving each result's position, title, URL, and snippet. section 11.4.2
  • Format those candidates into a readable prompt alongside the product search key. section 11.4.2
  • Tell the model to prefer official manufacturer pages, individual product pages, useful product fields, and stable URLs; reject reviews, forums, retailers when an official page exists, and category pages. section 11.4.2
  • Parse a structured response containing the selected URL, confidence, and reasoning so the decision can be reviewed or audited. section 11.4.2

Selecting a product URL

For GORUCK GR1 26L, the model would typically select the goruck.com product page with high confidence because it is the manufacturer's official page and likely contains the target fields. Review the reasoning, compare the choice with the raw search results, and sample results across larger batches before trusting the pipeline. section 11.4.2

Listing 11.2 Using an LLM to rank candidate URLs
 
import openai  #A
 
def format_candidate_urls(candidates: list[dict]) -> str:  #B
    blocks = []
    for candidate in candidates:  #C
        blocks.append(
            "\n".join(
                [
                    f"Position {candidate['position']}:",
                    f"  Title: {candidate['title']}",
                    f"  URL: {candidate['url']}",
                    f"  Snippet: {candidate['snippet']}",
                ]
            )
        )
    return "\n\n".join(blocks)
 
def rank_urls_with_ai(
    search_key: str,
    candidates: list[dict],
    model: str = "gpt-4o",
) -> URLRanking:  #D
    candidate_text = format_candidate_urls(candidates)  #E
 
    user_prompt = (
        f"Product search key: {search_key}\n\n"
        f"Candidate URLs:\n{candidate_text}"
    )  #F
 
    completion = openai.beta.chat.completions.parse(  #G
        model=model,
        messages=[
            {"role": "system", "content": URL_RANKING_SYSTEM_PROMPT},
            {"role": "user", "content": user_prompt},
        ],
        response_format=URLRanking,
    )
 
    return completion.choices[0].message.parsed  #H
 
ranking = rank_urls_with_ai(search_query, candidates)  #I
 
print(f"\nBest URL: {ranking.best_url}")
print(f"Confidence: {ranking.confidence}")
print(f"Reasoning: {ranking.reasoning}")
print("✓ URL selected for extraction")  #J

Use the complete Python pattern to format candidate dictionaries, call the model, and return a typed URLRanking result. section 11.4.2

How Learn AI Data Engineering covers it

How deep it goes
Explains prompt criteria, input formatting, structured output, and review, but stops short of eliminating manual validation.
Examples
Uses product search results, official manufacturer pages, GORUCK GR1 26L, and confidence-and-reasoning outputs.
What it assumes
Assumes basic search and HTML inspection, while deliberately demonstrating how AI reduces repetitive URL-selection judgment.
What you can do after
Build it from scratch as a Python pipeline that ranks candidate URLs and produces reviewable structured decisions.
How it connects
Connects web scraping with search results, structured data extraction, prompt design, and manual validation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI Data Engineering. The section links point to the parts of the book it draws on.