Add ChatContextOptions
to ChatOptions
#347
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.
Problem
There was a change made to the Assistant chat interface in the last release that were not captured in the TypeScript client -
topK
andsnippetSize
have been moved into acontext_options
value: https://docs.pinecone.io/reference/api/2025-04/assistant/chat_assistant#body-context-options. The client currently hastopK
at the top level of theChatOptions
payload.While cleaning this up I also noticed a few inconsistencies with how some things are being passed to the Assistant API which I've also addressed here. There's some added complexity in the TypeScript implementation for Assistant as the generated code did not fully cover implementation for streaming and file upload, so
chatStream
,chatCompletionStream
, anduploadFile
all usefetch
directly rather than plumbing through generated code.This looks to address this community post: https://community.pinecone.io/t/pinecone-assistant-chatstream-topk-and-snippet-size/8065/1
Solution
ChatContextOptions
as a new type which wrapstopK
andsnippetSize
. To keep this somewhat non-breaking, I've left thetopK
field at the top of theChatOptions
interface as well. There's a bit of logic to use this if present, and otherwise usecontextOptions.topK
. I wanted to keep things non-breaking so we could release this as a minor upgrade.chatStream
,chatCompletionStream
functions we need to manually convert the keys of the passed objects to snake case. The API is expecting snakecase, and normally the generated OpenAPI types handle this for us. Since we're not using those directly in these cases, we need to handle this ourselves. I had missed this previously, although I did handle converting responses from snake to camel where necessary. I know this is a bit confusing - apologies.context
function wasn't passingmessages
,topK
, orsnippetSize
properly. This was just a miss on my part.We need better testing coverage in general for assistant operations. The implementation was a bit rushed on my part earlier this year.
Type of Change
Test Plan
CI - external app tests, unit tests, integration tests
Manually tested using the assistant interface via repl. You can pull this branch down yourself and play around using
npm run repl
locally:Here are some examples with PINECONE_DEBUG output from my local runs: