Summary
The news embedding path in data/sources/news.py creates a new SentenceTransformer("all-MiniLM-L6-v2") model instance every time embed_headlines() is called.
This is unnecessary overhead for a module that is expected to process many headline batches and may be used repeatedly in the streaming ingestion pipeline.
Problem
The current implementation does the model initialization inside the function body:
SentenceTransformer(...) is constructed on every call,
which adds startup latency and repeated model load cost,
especially when the pipeline is invoked repeatedly for many tickers or repeated refresh cycles.
Expected behavior
The sentence-transformer model should be loaded once and reused across calls, ideally via:
a module-level singleton,
or a cached factory / @lru_cache wrapper.
This would reduce repeated initialization cost while keeping the interface unchanged.
Why this matters
This is a practical performance and reliability improvement for the data ingestion layer. The repo’s streaming and news pipeline is intended to support repeated headline processing, so avoiding repeated model reloads would make the pipeline much more efficient and stable.
Scope
This issue is focused on:
model lifecycle management,
performance improvement,
and keeping the API behavior unchanged for callers.
Suggested implementation direction
Move the SentenceTransformer creation to a cached module-level helper so that the model is instantiated once and reused across calls.
Shorter version
The news embedding path currently recreates the sentence-transformer model on every call to embed_headlines(). This introduces unnecessary startup cost in the ingestion pipeline. Please cache the model instance at module scope or via a cached factory so it is loaded once and reused across requests.
Summary
The news embedding path in data/sources/news.py creates a new SentenceTransformer("all-MiniLM-L6-v2") model instance every time embed_headlines() is called.
This is unnecessary overhead for a module that is expected to process many headline batches and may be used repeatedly in the streaming ingestion pipeline.
Problem
The current implementation does the model initialization inside the function body:
SentenceTransformer(...) is constructed on every call,
which adds startup latency and repeated model load cost,
especially when the pipeline is invoked repeatedly for many tickers or repeated refresh cycles.
Expected behavior
The sentence-transformer model should be loaded once and reused across calls, ideally via:
a module-level singleton,
or a cached factory / @lru_cache wrapper.
This would reduce repeated initialization cost while keeping the interface unchanged.
Why this matters
This is a practical performance and reliability improvement for the data ingestion layer. The repo’s streaming and news pipeline is intended to support repeated headline processing, so avoiding repeated model reloads would make the pipeline much more efficient and stable.
Scope
This issue is focused on:
model lifecycle management,
performance improvement,
and keeping the API behavior unchanged for callers.
Suggested implementation direction
Move the SentenceTransformer creation to a cached module-level helper so that the model is instantiated once and reused across calls.
Shorter version
The news embedding path currently recreates the sentence-transformer model on every call to embed_headlines(). This introduces unnecessary startup cost in the ingestion pipeline. Please cache the model instance at module scope or via a cached factory so it is loaded once and reused across requests.