- Home
- Skills
- Rshvr
- Unofficial Cohere Best Practices
- Cohere Typescript Sdk
cohere-typescript-sdk_skill
0
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill rshvr/unofficial-cohere-best-practices --skill cohere-typescript-sdk- SKILL.md6.6 KB
Overview
This skill is a practical reference for using the Cohere TypeScript/JavaScript SDK to build chat, streaming, embeddings, reranking, structured outputs, tool-enabled agents, and RAG pipelines. It consolidates installation, client setup, key API patterns, and recommended parameters for Node.js and browser projects. Use it to speed up integration and avoid common mistakes when calling Cohere APIs.
How this skill works
The skill documents how to initialize the Cohere client, call the chat and chatStream endpoints, generate embeddings (with explicit input types), perform reranking, and implement tool calls and structured JSON outputs. It shows batching patterns for embeddings, error handling classes, and examples for mapping tool function calls to local handlers. The examples focus on safe defaults and production-minded practices like batching, inputType selection, and streaming consumption.
When to use it
- Building a Node.js or browser app that needs chat, embeddings, or reranking with Cohere.
- Implementing retrieval-augmented generation (RAG) with document embeddings and query embeddings.
- Adding tool execution or function-like integrations to a chat agent.
- Streaming generated text to UIs or command-line consumers for lower latency.
- Producing structured JSON outputs validated against a schema for downstream systems.
Best practices
- Always set the correct embed inputType: use search_document for stored docs and search_query for user queries.
- Batch embeddings (max 96 items) to reduce API calls and respect rate limits.
- Use streaming (chatStream) to render tokens incrementally and improve perceived latency.
- Define tools with clear schemas and map toolCalls to deterministic local handlers.
- Handle CohereError and CohereTimeoutError explicitly to implement retries and fallback behavior.
Example use cases
- Create a RAG pipeline: embed documents, store vectors, embed queries, rerank results, and synthesize answers with chat.
- Build a chat assistant that invokes external tools (weather, calendar) via toolCall patterns and returns combined results.
- Stream long-form generation to a web UI for progressive rendering while writing to logs or storage.
- Extract structured data from text using responseFormat json_object and validate against a JSON schema.
- Rerank search results to surface the most relevant passages before generation or display.
FAQ
Use inputType: 'search_document' when embedding documents for storage and 'search_query' when embedding user queries for search; this ensures vectors are generated with the intended use case in mind.
How many items can I embed per request?
Batch up to 96 texts per embed request and implement batching logic to process larger collections.
How do I handle tool calls returned by chat?
Collect toolCalls from the assistant message, execute the mapped local function with parsed arguments, push a tool role message with the results, then continue the chat loop until no toolCalls remain.