Implementation:AI4Finance Foundation FinGPT similarity score
| 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
- Principle:AI4Finance_Foundation_FinGPT_Retrieval_Augmented_Generation
- Principle:AI4Finance_Foundation_FinGPT_Keyword_Extraction