You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This directory contains the **complete implementation and demonstration** of the dynamic-few shot prompting feature for GenAI IDP Accelerator. This feature enables users to dynamically retrieve few-shot examples using S3 Vectors similarity search to improve extraction accuracy for Pattern 2.
3
+
This directory contains the **complete implementation** of the dynamic few-shot prompting Lambda function for GenAI IDP Accelerator. This Lambda function integrates with Pattern 2 extraction as a custom prompt generator, dynamically retrieving similar examples using S3 Vectors similarity search to improve extraction accuracy.
4
4
5
5
## 🎯 Overview
6
6
7
-
The dynamic-few shot prompting feature allows you to:
7
+
The dynamic few-shot prompting Lambda function allows you to:
8
8
9
9
-**Dynamically retrieve similar examples** based on document content using vector similarity search
10
-
-**Provide few-shot examples**to improve extraction accuracy through example-based prompting
10
+
-**Automatically inject few-shot examples**into extraction prompts using the `{FEW_SHOT_EXAMPLES}` placeholder
11
11
-**Leverage S3 Vectors** for efficient similarity search across large example datasets
12
12
-**Integrate multimodal embeddings** using Amazon Nova models for image-based similarity
13
-
-**Customize example selection**based on document characteristics and business rules
13
+
-**Seamlessly integrate**with existing IDP extraction workflows as a custom prompt Lambda
14
14
15
15
## 📁 Files in This Directory
16
16
17
-
-**`GENAIIDP-dynamic-few-shot.py`** - Dynamic few-shot Lambda function with S3 Vectors lookup
18
-
-**`template.yml`** - CloudFormation SAM template to deploy the complete stack
19
-
-**`requirements.txt`** - Python dependencies for the Lambda function
17
+
-**`src/GENAIIDP-dynamic-few-shot.py`** - Dynamic few-shot Lambda function with S3 Vectors lookup
18
+
-**`src/requirements.txt`** - Python dependencies for the Lambda function
19
+
-**`template.yml`** - CloudFormation SAM template to deploy the Lambda function
20
20
-**`README.md`** - This comprehensive documentation and guide
Use the [fewshot_dataset_import.ipynb](notebooks/fewshot_dataset_import.ipynb) notebook to import a dataset into S3 Vectors, or manually upload your example documents and metadata to the S3 bucket and vector index created by the stack.
90
103
91
-
### Step 4: Configure IDP to Use Dynamic-few shot
104
+
### Step 4: Configure IDP to Use Dynamic Few-Shot
92
105
93
106
Add the Lambda ARN to your IDP extraction configuration:
**Critical**: Your extraction task prompt must include the `{FEW_SHOT_EXAMPLES}` placeholder where you want the dynamic examples to be inserted. The Lambda specifically looks for this placeholder and replaces it with retrieved examples.
406
+
342
407
### Expected Behavior
343
408
344
409
When configured:
345
410
1. IDP processes document and extracts images/text
346
-
2. Dynamic few-shot Lambda is invoked with document data
347
-
3. Lambda returns similar examples with prompts and images
348
-
4. IDP includes examples in extraction prompt to Bedrock
349
-
5. Bedrock uses examples to improve extraction accuracy
411
+
2. IDP invokes the dynamic few-shot Lambda with full extraction context
412
+
3. Lambda generates embeddings from document images using Amazon Nova
413
+
4. Lambda queries S3 Vectors to find similar examples
414
+
5. Lambda loads example images and metadata from S3
415
+
6. Lambda builds modified prompt content with examples inserted at `{FEW_SHOT_EXAMPLES}` location
416
+
7. IDP uses the modified prompt content for Bedrock extraction
417
+
8. Bedrock uses the dynamic examples to improve extraction accuracy
0 commit comments