`MaximalMarginalRelevance` makes 2N embedding calls instead of 1
Feature request
MaximalMarginalRelevance.extract_topics() calls the embedding model twice per topic: once for the individual candidate words and once for the concatenated sentence. With N topics, this means 2N separate embedding calls — each with its own model inference overhead, GPU kernel launch, or API round-trip (for remote embedding services like OpenAI).
Batch all words and all sentences across every topic into a single embedding call instead of 2N.
Motivation
For a typical run with 50 topics using OpenAI embeddings, this is 100 API calls where 1 would suffice. The improvement scales linearly with topic count and is most impactful with API-based embedding models where each call has network latency and rate-limiting overhead.
Your contribution
I can submit a PR that collects all candidate words and all topic sentences across all topics into a single flat list, makes 1 embedding call, then slices the result array back into per-topic chunks using pre-computed index ranges.
This reduces 2N calls to exactly 1 call, with identical output.
I've already been prototyping this in my fork, so I can open a PR quickly if this looks like a good direction.
Source: MaartenGr/BERTopic