黄腾 aopstudio Kevin Hu commited on
Commit
b6bfae8
·
1 Parent(s): 4636d13

add support for Voyage AI (#2159)

Browse files

### What problem does this PR solve?

#1853 #2138 add support for Voyage AI

### Type of change
- [x] New Feature (non-breaking change which adds functionality)

---------

Co-authored-by: Zhedong Cen <[email protected]>
Co-authored-by: Kevin Hu <[email protected]>

conf/llm_factories.json CHANGED
@@ -2400,7 +2400,7 @@
2400
  ]
2401
  },
2402
  {
2403
- "name": "Lepton",
2404
  "logo": "",
2405
  "tags": "LLM",
2406
  "status": "1",
@@ -3290,6 +3290,68 @@
3290
  "model_type": "chat"
3291
  }
3292
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3293
  }
3294
  ]
3295
  }
 
2400
  ]
2401
  },
2402
  {
2403
+ "name": "LeptonAI",
2404
  "logo": "",
2405
  "tags": "LLM",
2406
  "status": "1",
 
3290
  "model_type": "chat"
3291
  }
3292
  ]
3293
+ },
3294
+ {
3295
+ "name": "Voyage AI",
3296
+ "logo": "",
3297
+ "tags": "TEXT EMBEDDING, TEXT RE-RANK",
3298
+ "status": "1",
3299
+ "llm": [
3300
+ {
3301
+ "llm_name": "voyage-large-2-instruct",
3302
+ "tags": "TEXT EMBEDDING,16000",
3303
+ "max_tokens": 16000,
3304
+ "model_type": "embedding"
3305
+ },
3306
+ {
3307
+ "llm_name": "voyage-finance-2",
3308
+ "tags": "TEXT EMBEDDING,32000",
3309
+ "max_tokens": 32000,
3310
+ "model_type": "embedding"
3311
+ },
3312
+ {
3313
+ "llm_name": "voyage-multilingual-2",
3314
+ "tags": "TEXT EMBEDDING,32000",
3315
+ "max_tokens": 32000,
3316
+ "model_type": "embedding"
3317
+ },
3318
+ {
3319
+ "llm_name": "voyage-law-2",
3320
+ "tags": "TEXT EMBEDDING,16000",
3321
+ "max_tokens": 16000,
3322
+ "model_type": "embedding"
3323
+ },
3324
+ {
3325
+ "llm_name": "voyage-code-2",
3326
+ "tags": "TEXT EMBEDDING,16000",
3327
+ "max_tokens": 16000,
3328
+ "model_type": "embedding"
3329
+ },
3330
+ {
3331
+ "llm_name": "voyage-large-2",
3332
+ "tags": "TEXT EMBEDDING,16000",
3333
+ "max_tokens": 16000,
3334
+ "model_type": "embedding"
3335
+ },
3336
+ {
3337
+ "llm_name": "voyage-2",
3338
+ "tags": "TEXT EMBEDDING,4000",
3339
+ "max_tokens": 4000,
3340
+ "model_type": "embedding"
3341
+ },
3342
+ {
3343
+ "llm_name": "rerank-1",
3344
+ "tags": "RE-RANK, 8000",
3345
+ "max_tokens": 8000,
3346
+ "model_type": "rerank"
3347
+ },
3348
+ {
3349
+ "llm_name": "rerank-lite-1",
3350
+ "tags": "RE-RANK, 4000",
3351
+ "max_tokens": 4000,
3352
+ "model_type": "rerank"
3353
+ }
3354
+ ]
3355
  }
3356
  ]
3357
  }
rag/llm/__init__.py CHANGED
@@ -45,7 +45,8 @@ EmbeddingModel = {
45
  "Upstage": UpstageEmbed,
46
  "SILICONFLOW": SILICONFLOWEmbed,
47
  "Replicate": ReplicateEmbed,
48
- "BaiduYiyan": BaiduYiyanEmbed
 
49
  }
50
 
51
 
@@ -105,7 +106,7 @@ ChatModel = {
105
  "Tencent Hunyuan": HunyuanChat,
106
  "XunFei Spark": SparkChat,
107
  "BaiduYiyan": BaiduYiyanChat,
108
- "Anthropic": AnthropicChat
109
  }
110
 
111
 
@@ -120,7 +121,8 @@ RerankModel = {
120
  "cohere": CoHereRerank,
121
  "TogetherAI": TogetherAIRerank,
122
  "SILICONFLOW": SILICONFLOWRerank,
123
- "BaiduYiyan": BaiduYiyanRerank
 
124
  }
125
 
126
 
 
45
  "Upstage": UpstageEmbed,
46
  "SILICONFLOW": SILICONFLOWEmbed,
47
  "Replicate": ReplicateEmbed,
48
+ "BaiduYiyan": BaiduYiyanEmbed,
49
+ "Voyage AI": VoyageEmbed
50
  }
51
 
52
 
 
106
  "Tencent Hunyuan": HunyuanChat,
107
  "XunFei Spark": SparkChat,
108
  "BaiduYiyan": BaiduYiyanChat,
109
+ "Anthropic": VoyageChat,
110
  }
111
 
112
 
 
121
  "cohere": CoHereRerank,
122
  "TogetherAI": TogetherAIRerank,
123
  "SILICONFLOW": SILICONFLOWRerank,
124
+ "BaiduYiyan": BaiduYiyanRerank,
125
+ "Voyage AI": VoyageRerank
126
  }
127
 
128
 
rag/llm/embedding_model.py CHANGED
@@ -623,3 +623,24 @@ class BaiduYiyanEmbed(Base):
623
  np.array([r["embedding"] for r in res["data"]]),
624
  res["usage"]["total_tokens"],
625
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
  np.array([r["embedding"] for r in res["data"]]),
624
  res["usage"]["total_tokens"],
625
  )
626
+
627
+
628
+ class VoyageEmbed(Base):
629
+ def __init__(self, key, model_name, base_url=None):
630
+ import voyageai
631
+
632
+ self.client = voyageai.Client(api_key=key)
633
+ self.model_name = model_name
634
+
635
+ def encode(self, texts: list, batch_size=32):
636
+ res = self.client.embed(
637
+ texts=texts, model=self.model_name, input_type="document"
638
+ )
639
+ return np.array(res.embeddings), res.total_tokens
640
+
641
+ def encode_queries(self, text):
642
+ res = self.client.embed
643
+ res = self.client.embed(
644
+ texts=text, model=self.model_name, input_type="query"
645
+ )
646
+ return np.array(res.embeddings), res.total_tokens
rag/llm/rerank_model.py CHANGED
@@ -311,3 +311,19 @@ class BaiduYiyanRerank(Base):
311
  rank = np.array([d["relevance_score"] for d in res["results"]])
312
  indexs = [d["index"] for d in res["results"]]
313
  return rank[indexs], res["usage"]["total_tokens"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  rank = np.array([d["relevance_score"] for d in res["results"]])
312
  indexs = [d["index"] for d in res["results"]]
313
  return rank[indexs], res["usage"]["total_tokens"]
314
+
315
+
316
+ class VoyageRerank(Base):
317
+ def __init__(self, key, model_name, base_url=None):
318
+ import voyageai
319
+
320
+ self.client = voyageai.Client(api_key=key)
321
+ self.model_name = model_name
322
+
323
+ def similarity(self, query: str, texts: list):
324
+ res = self.client.rerank(
325
+ query=query, documents=texts, model=self.model_name, top_k=len(texts)
326
+ )
327
+ rank = np.array([r.relevance_score for r in res.results])
328
+ indexs = [r.index for r in res.results]
329
+ return rank[indexs], res.total_tokens
requirements.txt CHANGED
@@ -86,6 +86,7 @@ torch==2.3.0
86
  transformers==4.38.1
87
  umap==0.1.1
88
  volcengine==1.0.146
 
89
  webdriver_manager==4.0.1
90
  Werkzeug==3.0.3
91
  wikipedia==1.4.0
 
86
  transformers==4.38.1
87
  umap==0.1.1
88
  volcengine==1.0.146
89
+ voyageai==0.2.3
90
  webdriver_manager==4.0.1
91
  Werkzeug==3.0.3
92
  wikipedia==1.4.0
requirements_arm.txt CHANGED
@@ -141,6 +141,7 @@ loguru==0.7.2
141
  umap-learn
142
  fasttext==0.9.2
143
  volcengine==1.0.141
 
144
  opencv-python-headless==4.9.0.80
145
  readability-lxml==0.8.1
146
  html_text==0.6.2
 
141
  umap-learn
142
  fasttext==0.9.2
143
  volcengine==1.0.141
144
+ voyageai==0.2.3
145
  opencv-python-headless==4.9.0.80
146
  readability-lxml==0.8.1
147
  html_text==0.6.2
web/src/assets/svg/llm/{lepton.svg → lepton-ai.svg} RENAMED
File without changes
web/src/assets/svg/llm/voyage.svg ADDED
web/src/pages/user-setting/setting-model/constant.ts CHANGED
@@ -24,7 +24,7 @@ export const IconMap = {
24
  'LM-Studio': 'lm-studio',
25
  'OpenAI-API-Compatible': 'openai-api',
26
  cohere: 'cohere',
27
- Lepton: 'lepton',
28
  TogetherAI: 'together-ai',
29
  PerfXCloud: 'perfx-cloud',
30
  Upstage: 'upstage',
@@ -38,6 +38,7 @@ export const IconMap = {
38
  'Fish Audio': 'fish-audio',
39
  'Tencent Cloud': 'tencent-cloud',
40
  Anthropic: 'anthropic',
 
41
  };
42
 
43
  export const BedrockRegionList = [
 
24
  'LM-Studio': 'lm-studio',
25
  'OpenAI-API-Compatible': 'openai-api',
26
  cohere: 'cohere',
27
+ LeptonAI: 'lepton-ai',
28
  TogetherAI: 'together-ai',
29
  PerfXCloud: 'perfx-cloud',
30
  Upstage: 'upstage',
 
38
  'Fish Audio': 'fish-audio',
39
  'Tencent Cloud': 'tencent-cloud',
40
  Anthropic: 'anthropic',
41
+ 'Voyage AI': 'voyage',
42
  };
43
 
44
  export const BedrockRegionList = [