Repository navigation
perf: caching models - #224
Merged
Merged
Conversation
I can see it in the logs
Thomas-Rowlands
self-requested a review
October 23, 2026 11:21
Thomas-Rowlands
approved these changes
Oct 23, 2026
Thomas-Rowlands
left a comment
There was a problem hiding this comment.
LGTM Tests pass and the explanation for the changes sounds good.
|
🎉 This PR is included in version 1.2.5 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
For the search routes, an embedder/retriever was set up for each request, and a new llm and pipeline for every LLM request.
To start the fix, I moved these components out to a FastAPI
Depends()function, which is cached with lru_cache decorator.This did require me to change some of the logic of how these components work.
Previously, the pipelines took the search parameters as arguments on setup.
This wouldn't work with caching pipelines, unless you wanted to keep those parameters, so now the pipelines don't take any of the search parameters on startup, but only on running them.
This part actually doesn't save much time, as the pipeline setup is cheap.
Where this does save time is that haystack shouts at you if you try to add one of their components (which is how the retrievers are initialised) to more than one pipeline.
Then some of the tests needed changing.
The main one was that the logic limiting the number of results returned is all in the generated SQL, so making a python unit test for this no longer makes any sense, so this test was moved into an integration test that runs on the database instead.
This passes and the test also checks that restricting the domain works too.
Related Issues or other material
Related #220
Related #221
Related #222
Closes #220
Closes #221
Closes #222
✅ Added/updated tests?