Skip to content

Commit 85872a9

Browse files
jrj5423Mini256
andauthored
feat: support bedrock embedding model provider (#511)
Close #379 --------- Co-authored-by: Mini256 <minianter@foxmail.com>
1 parent 11852d1 commit 85872a9

8 files changed

Lines changed: 69 additions & 0 deletions

File tree

backend/app/rag/chat_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from llama_index.embeddings.openai import OpenAIEmbedding
1818
from llama_index.embeddings.jinaai import JinaEmbedding
1919
from llama_index.embeddings.cohere import CohereEmbedding
20+
from llama_index.embeddings.bedrock import BedrockEmbedding
2021
from llama_index.embeddings.ollama import OllamaEmbedding
2122
from llama_index.postprocessor.jinaai_rerank import JinaRerank
2223
from llama_index.postprocessor.cohere_rerank import CohereRerank
@@ -331,6 +332,14 @@ def get_embed_model(
331332
model_name=model,
332333
cohere_api_key=credentials,
333334
)
335+
case EmbeddingProvider.BEDROCK:
336+
return BedrockEmbedding(
337+
model_name=model,
338+
aws_access_key_id=credentials["aws_access_key_id"],
339+
aws_secret_access_key=credentials["aws_secret_access_key"],
340+
region_name=credentials["aws_region_name"],
341+
**config,
342+
)
334343
case EmbeddingProvider.OLLAMA:
335344
return OllamaEmbedding(
336345
model_name=model,

backend/app/rag/embed_model_option.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ class EmbeddingModelOption(BaseModel):
5757
credentials_type="str",
5858
default_credentials="*****",
5959
),
60+
EmbeddingModelOption(
61+
provider=EmbeddingProvider.BEDROCK,
62+
provider_display_name="Bedrock",
63+
provider_description="Amazon Bedrock is a fully managed foundation models service.",
64+
provider_url="https://docs.aws.amazon.com/bedrock/",
65+
default_embedding_model="amazon.titan-embed-text-v2:0",
66+
embedding_model_description="",
67+
credentials_display_name="AWS Bedrock Credentials JSON",
68+
credentials_description="The JSON Object of AWS Credentials, refer to https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-global",
69+
credentials_type="dict",
70+
default_credentials={
71+
"aws_access_key_id": "****",
72+
"aws_secret_access_key": "****",
73+
"aws_region_name": "us-west-2",
74+
},
75+
),
6076
EmbeddingModelOption(
6177
provider=EmbeddingProvider.OLLAMA,
6278
provider_display_name="Ollama",

backend/app/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class EmbeddingProvider(str, enum.Enum):
1515
OPENAI = "openai"
1616
JINA = "jina"
1717
COHERE = "cohere"
18+
BEDROCK = "bedrock"
1819
OLLAMA = "ollama"
1920
GITEEAI = "giteeai"
2021
LOCAL = "local"

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dependencies = [
5858
"retry>=0.9.2",
5959
"langchain-openai>=0.2.9",
6060
"ragas>=0.2.6",
61+
"llama-index-embeddings-bedrock<=0.3.0",
6162
]
6263
readme = "README.md"
6364
requires-python = ">= 3.8"

backend/requirements-dev.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ billiard==4.2.0
5454
# via celery
5555
boto3==1.34.156
5656
# via cohere
57+
# via llama-index-embeddings-bedrock
5758
# via llama-index-llms-bedrock
5859
botocore==1.34.156
5960
# via boto3
@@ -319,6 +320,7 @@ llama-index-core==0.11.10
319320
# via llama-index
320321
# via llama-index-agent-openai
321322
# via llama-index-cli
323+
# via llama-index-embeddings-bedrock
322324
# via llama-index-embeddings-cohere
323325
# via llama-index-embeddings-jinaai
324326
# via llama-index-embeddings-ollama
@@ -338,6 +340,7 @@ llama-index-core==0.11.10
338340
# via llama-index-readers-file
339341
# via llama-index-readers-llama-parse
340342
# via llama-parse
343+
llama-index-embeddings-bedrock==0.3.0
341344
llama-index-embeddings-cohere==0.2.0
342345
llama-index-embeddings-jinaai==0.3.0
343346
llama-index-embeddings-ollama==0.3.0

backend/requirements.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ billiard==4.2.0
5454
# via celery
5555
boto3==1.34.156
5656
# via cohere
57+
# via llama-index-embeddings-bedrock
5758
# via llama-index-llms-bedrock
5859
botocore==1.34.156
5960
# via boto3
@@ -319,6 +320,7 @@ llama-index-core==0.11.10
319320
# via llama-index
320321
# via llama-index-agent-openai
321322
# via llama-index-cli
323+
# via llama-index-embeddings-bedrock
322324
# via llama-index-embeddings-cohere
323325
# via llama-index-embeddings-jinaai
324326
# via llama-index-embeddings-ollama
@@ -338,6 +340,7 @@ llama-index-core==0.11.10
338340
# via llama-index-readers-file
339341
# via llama-index-readers-llama-parse
340342
# via llama-parse
343+
llama-index-embeddings-bedrock==0.3.0
341344
llama-index-embeddings-cohere==0.2.0
342345
llama-index-embeddings-jinaai==0.3.0
343346
llama-index-embeddings-ollama==0.3.0

frontend/app/src/pages/docs/embedding-model.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,34 @@ Cohere provides industry-leading large language models (LLMs) and RAG capabiliti
109109

110110
For more information, see the [Cohere Embed documentation](https://docs.cohere.com/docs/cohere-embed).
111111

112+
### Amazon Bedrock
113+
114+
Amazon Bedrock is a fully managed foundation models service that provides a range of large language models and embedding models.
115+
116+
**Featured Models**:
117+
118+
| Embedding Model | Vector Dimensions | Max Tokens |
119+
| ------------------------------- | ----------------- | ---------- |
120+
| `amazon.titan-embed-text-v2:0` | 1024 | 8192 |
121+
| `amazon.titan-embed-text-v1` | 1536 | 8192 |
122+
| `amazon.titan-embed-g1-text-02` | 1536 | 8192 |
123+
| `cohere.embed-english-v3` | 1024 | 512 |
124+
| `cohere.embed-multilingual-v3` | 1024 | 512 |
125+
126+
To check all embbeding models supported by Bedrock, go to [Bedrock console](https://console.aws.amazon.com/bedrock).
127+
128+
To use Amazon Bedrock, you'll need to provide a JSON Object of your AWS Credentials, as described in the [AWS CLI config global settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-global):
129+
130+
```json
131+
{
132+
"aws_access_key_id": "****",
133+
"aws_secret_access_key": "****",
134+
"aws_region_name": "us-west-2"
135+
}
136+
```
137+
138+
For more information, see the [Amazon Bedrock documentation](https://docs.aws.amazon.com/bedrock/).
139+
112140
### Ollama
113141

114142
Ollama is a lightweight framework for building and running large language models and embedding models locally.

frontend/app/src/pages/docs/llm.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ Currently Autoflow supports the following LLM providers:
3030
- [Google Gemini](https://gemini.google.com/)
3131
- [Anthropic Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude)
3232
- [Amazon Bedrock](https://aws.amazon.com/bedrock/)
33+
- To use Amazon Bedrock, you'll need to provide a JSON Object of your AWS Credentials, as described in the [AWS CLI config global settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-global):
34+
```json
35+
{
36+
"aws_access_key_id": "****",
37+
"aws_secret_access_key": "****",
38+
"aws_region_name": "us-west-2"
39+
}
40+
```
3341
- [Gitee AI](https://ai.gitee.com/serverless-api)
3442
- And all OpenAI-Like models:
3543
- [OpenRouter](https://openrouter.ai/)

0 commit comments

Comments
 (0)