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

Implementation:AI4Finance Foundation FinGPT similarity score

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

Overview

Concrete tool for computing word-overlap similarity between two text strings for relevance filtering in RAG pipelines provided by the FinGPT RAG scraper.

Description

The similarity_score function computes a lightweight word-overlap similarity between two strings. It splits both strings into words, counts matching words (where one word is a substring of the other), and normalizes by the minimum word count. This is used by the news scraper to filter articles by relevance to the query subject.

Articles with similarity >= threshold (0.8 for most sources, 0.75 for Google) are considered relevant; their text is appended to the subject as context.

Usage

Import this function when you need to filter articles by relevance:

  • News scraping: Filtering scraped articles by similarity to query.
  • Relevance thresholding: Determining whether retrieved context is relevant.

Code Reference

Source Location

  • Repository: FinGPT
  • File: fingpt/FinGPT_RAG/multisource_retrieval/scrapers/similarity_score.py (L1-13), fingpt/FinGPT_RAG/multisource_retrieval/news_scraper.py (L50-62)

Signature

def similarity_score(
    a: str,
    b: str,
) -> float

Import

from scrapers.similarity_score import similarity_score

I/O Contract

Inputs

Name Type Required Description
a str Yes First text (e.g., article text)
b str Yes Second text (e.g., query subject)

Outputs

Name Type Description
return value float Similarity score in [0, 1]

Usage Examples

Filter Article by Relevance

from scrapers.similarity_score import similarity_score

article = "Apple reported record quarterly earnings beating expectations"
query = "Apple quarterly earnings report"

score = similarity_score(article, query)
print(score)  # e.g., 0.85

if score >= 0.8:
    print("Article is relevant")

Related Pages

Implements Principle

Uses Heuristic

Page Connections

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