Member Junction
    Preparing search index...

    Module @memberjunction/ai-cohere - v6.2.0

    @memberjunction/ai-cohere

    MemberJunction AI provider for Cohere. It implements BaseReranker for semantic document reranking (Cohere Rerank API) and BaseEmbeddings for text and multimodal embeddings (Cohere Embed v4), useful for improving relevance and powering retrieval in RAG (Retrieval-Augmented Generation) pipelines.

    graph TD
        A["CohereReranker
    (Provider)"] -->|extends| B["BaseReranker
    (@memberjunction/ai)"] A -->|wraps| C["CohereClient
    (cohere-ai SDK)"] C -->|calls| D["Cohere Rerank API"] D -->|returns| E["Ranked Documents
    with Relevance Scores"] B -->|registered via| F["@RegisterClass"] style A fill:#7c5295,stroke:#563a6b,color:#fff style B fill:#2d6a9f,stroke:#1a4971,color:#fff style C fill:#2d8659,stroke:#1a5c3a,color:#fff style D fill:#2d8659,stroke:#1a5c3a,color:#fff style E fill:#b8762f,stroke:#8a5722,color:#fff style F fill:#b8762f,stroke:#8a5722,color:#fff
    • Semantic Reranking: Reorder documents by relevance to a query using neural models
    • Multiple Models: rerank-v5.0-fast (default) and rerank-v5.0-pro, rerank-v4.0-fast and rerank-v4.0-pro, and the legacy rerank-v3.5 and rerank-multilingual-v3.0
    • Relevance Scoring: Documents scored 0-1 with fine-grained relevance ranking
    • RAG Pipeline Integration: Designed for use in retrieval-augmented generation workflows
    • Context Focus: with Rerank 5, optional passage spans per document (the RelevantSpans option)
    • Multimodal Embeddings: Embed text and images into a shared vector space (Cohere Embed v4)
    • Text and Batch: Single and batch text embedding (1536-dim default)
    • Configurable Input Type: Optimize embeddings for document storage or query retrieval
    npm install @memberjunction/ai-cohere
    
    import { CohereReranker } from '@memberjunction/ai-cohere';

    const reranker = new CohereReranker('your-cohere-api-key', 'rerank-v5.0-fast');

    const results = await reranker.Rerank({
    query: 'What is the capital of France?',
    documents: [
    { id: '1', text: 'Paris is the capital of France.' },
    { id: '2', text: 'London is the capital of England.' },
    { id: '3', text: 'France is a country in Europe.' }
    ],
    topK: 5
    });

    // Results sorted by relevance score (0-1)
    for (const result of results) {
    console.log(`${result.documentId}: ${result.relevanceScore}`);
    }
    import { CohereEmbedding } from '@memberjunction/ai-cohere';

    const embedding = new CohereEmbedding('your-cohere-api-key');

    // Text (1536-dim vector)
    const text = await embedding.EmbedText({ text: 'a golden retriever in the snow' });

    // Multimodal: text + image fused into ONE vector
    const multimodal = await embedding.EmbedContent({
    content: [
    { type: 'text', content: 'product photo:' },
    { type: 'image_url', content: '<base64-image>', mimeType: 'image/png' },
    ],
    });
    console.log(multimodal.vector.length); // 1536
    Model Description
    rerank-v5.0-fast Rerank 5, high throughput, 32K context, Context Focus (default)
    rerank-v5.0-pro Rerank 5 flagship, 32K context, Context Focus
    rerank-v4.0-fast Previous generation, fast, 32K context
    rerank-v4.0-pro Previous generation flagship, 32K context
    rerank-v3.5 Legacy English reranker, 4K context (deprecated upstream)
    rerank-multilingual-v3.0 Legacy multilingual reranker, 4K context
    • CohereReranker -- Registered as CohereReranker, the driver class on the Cohere reranker model-vendor rows, and as CohereLLM. Its legacy environment-variable key is AI_VENDOR_API_KEY__COHERERERANKER.
    • CohereEmbedding -- Registered via @RegisterClass(BaseEmbeddings, 'CohereEmbedding').
    • @memberjunction/ai - Core AI abstractions (BaseReranker)
    • @memberjunction/global - Class registration
    • cohere-ai - Official Cohere SDK

    Classes

    CohereEmbedding
    CohereReranker

    Interfaces

    CohereRelevantSpan
    CohereRelevantSpansOptions
    CohereRerankOptions

    Functions

    createCohereReranker
    CreateCohereReranker