Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:AI4Finance Foundation FinGPT Relevance Thresholding

From Leeroopedia
Knowledge Sources
Domains NLP, RAG, Sentiment_Analysis
Last Updated 2026-10-18 00:00 GMT

Overview

Use word-overlap similarity scoring to filter and rank scraped news articles by relevance to the target financial subject before sentiment classification.

Description

The RAG multisource retrieval pipeline computes a similarity score between the target subject and scraped article content using word-level overlap. The `similarity_score` function counts matching words (using substring containment in both directions) and divides by the minimum word count of the two strings. Articles below a relevance threshold can be filtered out before being sent to the LLM for sentiment classification, reducing API costs and improving classification accuracy.

Usage

Use this heuristic when filtering scraped news articles for relevance to a target subject before LLM-based sentiment classification. Apply during the `scraping_by_url` workflow.

The Insight (Rule of Thumb)

  • Action: Compute `similarity_score(subject, article_content)` and filter articles below a threshold.
  • Value: Score = matching_words / min(len(words_a), len(words_b)); threshold typically > 0 for relevance.
  • Trade-off: Word-overlap is simple but misses semantic relevance (synonyms, paraphrasing); may miss relevant articles with different vocabulary.
  • Compatibility: Works with any text; used in the RAG multisource retrieval pipeline.

Reasoning

Scraping news from multiple sources (Yahoo, CNBC, MarketScreener, Seeking Alpha, Google) returns many articles that are not relevant to the target subject. Sending all articles to an LLM for classification wastes API calls and introduces noise. Word-overlap similarity is a fast, zero-cost pre-filter that identifies articles sharing vocabulary with the target subject. While not as accurate as embedding-based similarity, it requires no model and runs in milliseconds.

Code Evidence

Similarity score function from `fingpt/FinGPT_RAG/multisource_retrieval/scrapers/similarity_score.py:1-13`:

def similarity_score(a, b):
    words_a = a.split()
    words_b = b.split()
    matching_words = 0

    for word_a in words_a:
        for word_b in words_b:
            if word_a in word_b or word_b in word_a:
                matching_words += 1
                break

    similarity = matching_words / min(len(words_a), len(words_b))
    return similarity

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment