chat: fix localdocs breakage in v3.5.2 #3302
Merged
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.
In v3.5.0 and v3.5.1, the API server incorrectly used the entire ChatModel to generate a response, which included messages from previous, unrelated chat sessions.
In v3.5.2, this was fixed but it consolidated the chat model access in a way that broke LocalDocs, by copying the messages before the sources had been added in promptInternalChat, which are necessary to generate the correct combined prompt for RAG.
With this PR, the early copy is replaced with a lambda to access the relevant part of the ChatModel. The API server selects the relevant messages by their indices instead of passing in a copy of them.
I have confirmed that LocalDocs does not seem to use the sources at all in v3.5.2, but with this PR it uses the sources appropriately both with a regular chat and via the local API server.