Commit cbca6e8
authored
Add network embedding batching (#276)
When using Mistral embedding API (through
[LiteLLM](https://www.litellm.ai/) for OpenAI API compatibility) with
Context Chat, I got many `Too many tokens overall, split into more
batches` errors.
This is due to Mistral's lower tokens limit per API request,
[16000~](langchain-ai/langchain#20523),
compared to OpenAI's
[300000](https://github.com/langchain-ai/langchain/blob/18230f625f79aba25cbf9fb5500ab504cbb8f0bc/libs/partners/openai/langchain_openai/embeddings/base.py#L22).
The idea to fix this is to implement the same pattern as the [LangChain
OpenAI
integration](https://github.com/langchain-ai/langchain/blob/18230f625f79aba25cbf9fb5500ab504cbb8f0bc/libs/partners/openai/langchain_openai/embeddings/base.py#L598),
batching API requests.
A better solution would be to allow using LangChain’s built-in provider
class, but this refactor is too big for my first PR x)
Signed-off-by: Florian Charlaix <fcharlaix@open-dsi.fr>1 parent 257c5ce commit cbca6e8
5 files changed
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
121 | 129 | | |
122 | 130 | | |
123 | 131 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
0 commit comments