@memberjunction/ai-cohere 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @memberjunction/ai-cohere
|
|
2
|
+
|
|
3
|
+
MemberJunction AI provider for Cohere's reranking capabilities. This package implements the `BaseReranker` interface to provide semantic document reranking using Cohere's Rerank API, useful for improving search result relevance in RAG (Retrieval-Augmented Generation) pipelines.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
graph TD
|
|
9
|
+
A["CohereReranker<br/>(Provider)"] -->|extends| B["BaseReranker<br/>(@memberjunction/ai)"]
|
|
10
|
+
A -->|wraps| C["CohereClient<br/>(cohere-ai SDK)"]
|
|
11
|
+
C -->|calls| D["Cohere Rerank API"]
|
|
12
|
+
D -->|returns| E["Ranked Documents<br/>with Relevance Scores"]
|
|
13
|
+
B -->|registered via| F["@RegisterClass"]
|
|
14
|
+
|
|
15
|
+
style A fill:#7c5295,stroke:#563a6b,color:#fff
|
|
16
|
+
style B fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
17
|
+
style C fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
18
|
+
style D fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
19
|
+
style E fill:#b8762f,stroke:#8a5722,color:#fff
|
|
20
|
+
style F fill:#b8762f,stroke:#8a5722,color:#fff
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Semantic Reranking**: Reorder documents by relevance to a query using neural models
|
|
26
|
+
- **Multiple Models**: Support for `rerank-v3.5` (English) and `rerank-multilingual-v3.0` (100+ languages)
|
|
27
|
+
- **Relevance Scoring**: Documents scored 0-1 with fine-grained relevance ranking
|
|
28
|
+
- **RAG Pipeline Integration**: Designed for use in retrieval-augmented generation workflows
|
|
29
|
+
- **Context-Aware**: Enhanced query processing for better relevance evaluation
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @memberjunction/ai-cohere
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { CohereReranker } from '@memberjunction/ai-cohere';
|
|
41
|
+
|
|
42
|
+
const reranker = new CohereReranker('your-cohere-api-key', 'rerank-v3.5');
|
|
43
|
+
|
|
44
|
+
const results = await reranker.Rerank({
|
|
45
|
+
query: 'What is the capital of France?',
|
|
46
|
+
documents: [
|
|
47
|
+
{ id: '1', text: 'Paris is the capital of France.' },
|
|
48
|
+
{ id: '2', text: 'London is the capital of England.' },
|
|
49
|
+
{ id: '3', text: 'France is a country in Europe.' }
|
|
50
|
+
],
|
|
51
|
+
topK: 5
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Results sorted by relevance score (0-1)
|
|
55
|
+
for (const result of results) {
|
|
56
|
+
console.log(`${result.documentId}: ${result.relevanceScore}`);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Supported Models
|
|
61
|
+
|
|
62
|
+
| Model | Description |
|
|
63
|
+
|-------|-------------|
|
|
64
|
+
| `rerank-v3.5` | Latest English reranker with best accuracy (default) |
|
|
65
|
+
| `rerank-multilingual-v3.0` | Supports 100+ languages |
|
|
66
|
+
|
|
67
|
+
## Class Registration
|
|
68
|
+
|
|
69
|
+
Registered as `CohereLLM` via `@RegisterClass(BaseReranker, 'CohereLLM')`.
|
|
70
|
+
|
|
71
|
+
## Dependencies
|
|
72
|
+
|
|
73
|
+
- `@memberjunction/ai` - Core AI abstractions (BaseReranker)
|
|
74
|
+
- `@memberjunction/global` - Class registration
|
|
75
|
+
- `cohere-ai` - Official Cohere SDK
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-cohere",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"description": "MemberJunction: Cohere AI Provider - Semantic reranking using Cohere's Rerank API",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"author": "MemberJunction.com",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@memberjunction/ai": "4.
|
|
20
|
-
"@memberjunction/global": "4.
|
|
19
|
+
"@memberjunction/ai": "4.2.0",
|
|
20
|
+
"@memberjunction/global": "4.2.0",
|
|
21
21
|
"cohere-ai": "^7.20.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|