待翻譯:Implement vector-prompt document classification using Amazon Bedrock
AI 服務暫時不可用,以下為來源摘要,待恢復後補全翻譯:Learn how to build a multi-agent document classification solution on Amazon Bedrock using the Strands Agents SDK. Three specialized agents combine textual analysis with Claude Haiku 4.5 and visual similarity search with Amazon Titan Multimodal Embeddings to accurately classify insurance documents such as policies and affidavits.
AI 服務暫時不可用,以下為來源正文,待恢復後補全翻譯。
Vector-prompt classification on Amazon Bedrock helps insurance companies accurately classify thousands of daily documents: policies, affidavits, endorsements, and regulatory forms, for compliance, claims, and customer service. Manual classification is time-consuming and error-prone, while traditional automated approaches struggle with documents that look similar but serve different purposes. A policy endorsement and a regulatory affidavit might contain similar terminology, yet misclassifying them can lead to compliance violations or processing delays. This post demonstrates how you can build a multi-agent solution using the Strands Agents SDK. The solution orchestrates three specialized agents: a Document Analysis Agent for textual reasoning, a Vector Similarity Search Agent for layout pattern recognition, and a Validation Agent for quality assurance. Each agent operates autonomously within its expertise, then collaborates through an Orchestrator to deliver results. You will learn how to implement this multi-agent architecture for your own document classification needs, with code examples and technical guidance. This multi-agent approach combines the advanced reasoning capabilities of Anthropic’s Claude Haiku 4.5 with the visual pattern recognition of Amazon Titan Multimodal Embeddings available on Amazon Bedrock to achieve better classification accuracy. Solution overview The solution architecture combines multiple specialized AI agents, each optimized for specific aspects of document analysis, working together through coordinated orchestration. This multi-agent approach addresses the limitations of single-model classification by using the unique strengths of different foundation models and techniques available through Amazon Bedrock. The following diagram illustrates the multi-agent approach: Figure 1: Multi-agent document classification architecture Multi-agent coordination with the Strands Agents SDK In our testing, single-model approaches struggled with edge cases and complex documents that require both textual and visual analysis. Multi-agent systems address this by breaking down the classification task into specialized subtasks, with each agent focusing on its area of expertise. We chose the Strands Agents SDK because it implements the agents as tools and our classification system needs an orchestrator that can invoke specialized agents as callable tools. The Validation Agent calls each specialist, compares their classifications, and resolves disagreements without custom orchestration code. This pattern offers several advantages: Modularity: Each agent can be developed, tested, and improved independently. Transparency: Every agent provides reasoning for its decisions, creating an audit trail. Flexibility: New agents can be added without restructuring the entire system. Reliability: The orchestrator handles agent coordination, error handling, and result synthesis. Architecture components At the core of the architecture is Validation Agent, which acts as an orchestrator and implements the agents as tools pattern using the Strands Agents SDK. This agent provides quality assurance through cross-validation and confidence scoring. It compares the outputs from both the Document Analysis Agent and Vector Similarity Search Agent. It identifies areas of agreement and disagreement, then generates a final classification with an associated confidence score. This validation step helps the system maintain high accuracy while flagging edge cases for human review. The Validation Agent coordinates with two specialized agents: Document Analysis Agent: This agent uses Anthropic’s Claude Haiku 4.5 on Amazon Bedrock for advanced textual reasoning and legal language interpretation. Claude excels at understanding complex documents, extracting key information, and identifying subtle patterns in text that indicate document type. The agent analyzes document content, metadata, and linguistic features to generate classification hypotheses. Vector Similarity Search Agent: This agent uses Amazon Titan Multimodal Embeddings G1 to convert documents into high-dimensional vector representations for visual similarity search. Claude Haiku 4.5 excels at understanding document content: analyzing text, extracting key information, and identifying linguistic patterns. The Vector Similarity Search Agent complements this by focusing on visual and structural characteristics. This agent captures how documents look rather than what they say. It identifies formatting patterns like form layouts, table structures, and formatting conventions that distinguish document types even when textual content varies. The agent uses FAISS (Facebook AI Similarity Search) for efficient vector similarity search, which supports rapid comparison against known document templates. By combining textual and similarity analysis with built-in validation, this multi-agent architecture achieves higher classification accuracy and provides reliable confidence scores for automated decision-making. In the next sections, you will learn how to implement each component and deploy the complete solution. Prerequisites To follow along with this walkthrough, you will need the following: AWS account and permissions An active AWS account with permissions to access Amazon Bedrock. AWS Identity and Access Management (IAM) permissions to create and invoke foundation models (FMs). Access to Anthropic’s Claude Haiku 4.5 and Amazon Titan Multimodal Embeddings models. For model availability by AWS Region, see Supported models by AWS Region in Amazon Bedrock. Development environment Python 3.14 or later installed. AWS CLI version 2.0 or later, configured with your credentials. An integrated development environment (IDE) or text editor (such as VS Code or PyCharm). Git for cloning the sample repository. Software and libraries Strands Agents SDK (installation instructions provided in the walkthrough). FAISS library for vector similarity search. Note: This walkthrough uses AWS services that might incur costs. Make sure to review the pricing for Amazon Bedrock and follow the cleanup instructions at the end to avoid ongoing charges. Implementing the multi-agent document classification system Let’s walk through implementing each component of the multi-agent system. The complete code is available in our GitHub repository. Step 1: Configure the foundation models First, configure access to the Claude model through an Amazon Bedrock inference profile. This provides consistent performance and availability across Regions. def create_bedrock_model( model_id: str = "anthropic.claude-haiku-4-5-20251001-v1:0", # temperature: float = 0.1, max_tokens: int = 4096 ) -> BedrockModel: """Create a configured Bedrock model instance.""" return BedrockModel( model_id=model_id, region_name="us-east-1", temperature=temperature, max_tokens=max_tokens ) Tip: For lower latency and higher availability (HA), you can use a cross-Region inference profile by adding a geographic prefix (us., eu., or ap.) that matches your deployment Region to the model ID. Step 2: Create the Document Analysis Agent The Document Analysis Agent specializes in textual content analysis using the advanced reasoning capabilities of Claude Haiku 4.5. The agent uses structured output to return consistent, machine-parseable classification results. class TextualAnalysisOutput(BaseModel): """Structured output for document text analysis.""" classification: str = Field(description="Document category: POLICY, AFFIDAVIT, or MISCELLANEOUS") confidence: float = Field(description="Classification confidence score from 0.0 to 1.0") reasoning: str = Field(description="Explanation of textual features that led to this classification") @tool def analyze_document_text(document_text: str) -> str: """Analyze document text content to classify the insurance document.""" TEXTUAL_ANALYSIS_PROMPT = """You are a Document Analysis Specialist for insurance documents. Analyze the provided document text and classify it into exactly one category: - POLICY: Insurance policies, endorsements, declarations, coverage documents - AFFIDAVIT: Sworn statements, notarized documents, legal declarations, regulatory filings - MISCELLANEOUS: Any document that doesn't clearly fit the above categories Provide your classification with a confidence score (0.0-1.0) and detailed reasoning explaining what textual features led to your decision.""" text_agent = Agent( model=create_bedrock_model(), system_prompt=TEXTUAL_ANALYSIS_PROMPT, conversation_manager=NullConversationManager(), ) result = text_agent( f"Classify this document:\n\n{document_text}", structured_output_model=TextualAnalysisOutput, ) return str(result.structured_output) Step 3: Build the Vector Similarity Search Agent The Vector Similarity Search Agent uses Amazon Titan Multimodal Embeddings to analyze document layout and visual characteristics. # Load FAISS index once at module level. # allow_dangerous_deserialization=True is required because FAISS uses pickle internally; # safe here since we created the index ourselves from our own training documents. db = FAISS.load_local("hybrid_docs.vdb", embeddings=embeddings, allow_dangerous_deserialization=True) VECTOR_ANALYSIS_PROMPT = """You are a Vector Similarity Search Specialist. Analyze the similarity search results and determine the document classification. Consider the confidence scores and consistency of matches across pages.""" @tool def analyze_document_vectors(pdf_path: str) -> str: """Classify document using vector similarity search with agentic reasoning.""" base64_pages = pdf_to_base64(pdf_path) first_embedding = create_multimodal_embedding(image_base64=base64_pages[0]) results = db.similarity_search_by_vector(embedding=first_embedding, k=3) labels = [r.metadata["label"] for r in results] classification = Counter(labels).most_common(1)[0][0] confidence = labels.count(classification) / len(labels) vector_agent = Agent( model=create_bedrock_model(), system_prompt=VECTOR_ANALYSIS_PROMPT, conversation_manager=NullConversationManager(), ) result = vector_agent( f"Vector search results for {pdf_path}:\n" f"Top match: {classification} (confidence: {confidence:.2f})\n" f"All matches: {labels}\n" f"Provide final classification with reasoning.", structured_output_model=VectorAnalysisOutput, ) return str(result.structured_output) This agent performs FAISS vector similarity search using perform_vector_classification to match documents against pre-trained visual patterns stored in the vector database. Step 4: Implement the Validation Agent The Validation Agent coordinates the specialist agents using the agents as tools pattern. class OrchestratorOutput(BaseModel): """Structured output for the validation orchestrator.""" textual_analysis: str = Field(description="Textual agent classification: POLICY, AFFIDAVIT, or MISCELLANEOUS") textual_confidence: float = Field(description="Textual agent confidence 0.0-1.0") vector_analysis: str = Field(description="Vector agent classification: POLICY, AFFIDAVIT, or MISCELLANEOUS") vector_confidence: float = Field(description="Vector agent confidence 0.0-1.0") final_classification: str = Field(description="Final validated classification") confidence: float = Field(description="Overall confidence score") requires_human_review: bool = Field(description="Whether edge case needs human review") decision_logic: str = Field(description="Brief explanation of decision") justification: str = Field(description="Detailed reasoning from both specialists") class MultiAgentDocumentClassifier: def init(self, model=None): self.model = model or create_bedrock_model() self.orchestrator = Agent( model=self.model, tools=[analyze_document_text, analyze_document_vectors], system_prompt="""You are a Document Classification Orchestrator. Your workflow: 1. Use analyze_document_text for textual analysis 2. Use analyze_document_vectors for visual similarit [truncated for AI cost control]