mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-01 11:02:37 +00:00
docs: update integration api refs (#25195)
- [x] toolkits - [x] retrievers (in this repo)
This commit is contained in:
@@ -19,11 +19,18 @@ class RetrievalConfig(BaseModel, extra="allow"): # type: ignore[call-arg]
|
||||
|
||||
|
||||
class AmazonKnowledgeBasesRetriever(BaseRetriever):
|
||||
"""`Amazon Bedrock Knowledge Bases` retrieval.
|
||||
"""Amazon Bedrock Knowledge Bases retriever.
|
||||
|
||||
See https://aws.amazon.com/bedrock/knowledge-bases for more info.
|
||||
|
||||
Args:
|
||||
Setup:
|
||||
Install ``langchain-aws``:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install -U langchain-aws
|
||||
|
||||
Key init args:
|
||||
knowledge_base_id: Knowledge Base ID.
|
||||
region_name: The aws region e.g., `us-west-2`.
|
||||
Fallback to AWS_DEFAULT_REGION env variable or region specified in
|
||||
@@ -35,7 +42,7 @@ class AmazonKnowledgeBasesRetriever(BaseRetriever):
|
||||
client: boto3 client for bedrock agent runtime.
|
||||
retrieval_config: Configuration for retrieval.
|
||||
|
||||
Example:
|
||||
Instantiate:
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_community.retrievers import AmazonKnowledgeBasesRetriever
|
||||
@@ -48,7 +55,48 @@ class AmazonKnowledgeBasesRetriever(BaseRetriever):
|
||||
}
|
||||
},
|
||||
)
|
||||
"""
|
||||
|
||||
Usage:
|
||||
.. code-block:: python
|
||||
|
||||
query = "..."
|
||||
|
||||
retriever.invoke(query)
|
||||
|
||||
Use within a chain:
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_aws import ChatBedrockConverse
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_core.prompts import ChatPromptTemplate
|
||||
from langchain_core.runnables import RunnablePassthrough
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
prompt = ChatPromptTemplate.from_template(
|
||||
\"\"\"Answer the question based only on the context provided.
|
||||
|
||||
Context: {context}
|
||||
|
||||
Question: {question}\"\"\"
|
||||
)
|
||||
|
||||
llm = ChatBedrockConverse(
|
||||
model_id="anthropic.claude-3-5-sonnet-20240620-v1:0"
|
||||
)
|
||||
|
||||
def format_docs(docs):
|
||||
return "\\n\\n".join(doc.page_content for doc in docs)
|
||||
|
||||
chain = (
|
||||
{"context": retriever | format_docs, "question": RunnablePassthrough()}
|
||||
| prompt
|
||||
| llm
|
||||
| StrOutputParser()
|
||||
)
|
||||
|
||||
chain.invoke("...")
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
knowledge_base_id: str
|
||||
region_name: Optional[str] = None
|
||||
|
Reference in New Issue
Block a user