sourcegraph / cody

Type less, code more: Cody is an AI code assistant that uses advanced search and codebase context to help you write and fix code.
https://cody.dev
Apache License 2.0
2.59k stars 275 forks source link

feat(perf): adds `CachedRetriever` #4608

Closed jamesmcnamara closed 3 months ago

jamesmcnamara commented 3 months ago

Adds a base class for retrievers that handles caching and cache invalidation.

The target for this is Jaccard similarity, however that retriever has a lot of dependencies on files. So instead of trying to collect all of the external deps, I added some mock VSCode APIs, so that when accessing files or tabs, we automatically start tracking those as dependencies for the current retrieval and subscribe to changes in those. Currently we handle that pretty crudely, but it could be expanded to handle more fine grained dependencies.

EDIT: It's a bit hard to read the diff for JaccardSimilarityRetriever because I moved the getRelevantFiles function in as a method so it could access the tracking methods. The only difference is s/vscode.workspace/this.workspace/ and similarly for window

TODO:

Closes https://linear.app/sourcegraph/issue/CODY-2228/[autocomplete-latency]-add-additional-caching-to-the-jaccard

Test plan

Added unit tests and manually tested.

valerybugakov commented 3 months ago

Linked the Linear issue to the description.