Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amazon.Runtime.Documents.InvalidDocumentTypeConversionException #3694

Open
1 task
phspies opened this issue Mar 6, 2025 · 4 comments
Open
1 task

Amazon.Runtime.Documents.InvalidDocumentTypeConversionException #3694

phspies opened this issue Mar 6, 2025 · 4 comments
Assignees
Labels
bug This issue is a bug. module/sdk-generated needs-reproduction This issue needs reproduction. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@phspies
Copy link

phspies commented Mar 6, 2025

Describe the bug

When using the the RetrievalFilter class for a Bedrock KnowledgeBase request it seems the key, value requires that you use the Amazon.Runtime.Documents.Document class within the filter structure. When attempting to use this filtering class the KnowledgeBase service seemed to ignore my filters but after further investigation, it seems the document class cannot be serialized. While trying to troubleshoot the problem I got this exception:

Amazon.Runtime.Documents.InvalidDocumentTypeConversionException: Cannot Convert DocumentType to List because it is String

I tried using this Document class multiple ways but it fails all the same:

retrievalFilter.Equals = new FilterAttribute
                {
                    Key = "TeamId",
                    Value = new Document(teamsId.ToString())
                };

This also fails

retrievalFilter.Equals = new FilterAttribute
                {
                    Key = "TeamId",
                    Value = teamsId.ToString()
                };

When I serialize the object using Serliog's internal serializer, it works but my filter values are empty:

{
    "Input": {
        "Text": "what is the diagrams about",
        "$type": "RetrieveAndGenerateInput"
    },
    "RetrieveAndGenerateConfiguration": {
        "ExternalSourcesConfiguration": null,
        "KnowledgeBaseConfiguration": {
            "GenerationConfiguration": null,
            "KnowledgeBaseId": "28W0R6NFGO",
            "ModelArn": "anthropic.claude-3-sonnet-20240229-v1:0",
            "OrchestrationConfiguration": null,
            "RetrievalConfiguration": {
                "VectorSearchConfiguration": {
                    "Filter": {
                        "AndAll": [
                            {
                                "AndAll": null,
                                "Equals": {
                                    "Key": "TeamId",
                                    "Value": [
                                        null
                                    ],
                                    "$type": "FilterAttribute"
                                },
                                "GreaterThan": null,
                                "GreaterThanOrEquals": null,
                                "In": null,
                                "LessThan": null,
                                "LessThanOrEquals": null,
                                "ListContains": null,
                                "NotEquals": null,
                                "NotIn": null,
                                "OrAll": null,
                                "StartsWith": null,
                                "StringContains": null,
                                "$type": "RetrievalFilter"
                            },
                            {
                                "AndAll": null,
                                "Equals": {
                                    "Key": "MeetingId",
                                    "Value": [
                                        null
                                    ],
                                    "$type": "FilterAttribute"
                                },
                                "GreaterThan": null,
                                "GreaterThanOrEquals": null,
                                "In": null,
                                "LessThan": null,
                                "LessThanOrEquals": null,
                                "ListContains": null,
                                "NotEquals": null,
                                "NotIn": null,
                                "OrAll": null,
                                "StartsWith": null,
                                "StringContains": null,
                                "$type": "RetrievalFilter"
                            }
                        ],
                        "Equals": null,
                        "GreaterThan": null,
                        "GreaterThanOrEquals": null,
                        "In": null,
                        "LessThan": null,
                        "LessThanOrEquals": null,
                        "ListContains": null,
                        "NotEquals": null,
                        "NotIn": null,
                        "OrAll": null,
                        "StartsWith": null,
                        "StringContains": null,
                        "$type": "RetrievalFilter"
                    },
                    "ImplicitFilterConfiguration": null,
                    "NumberOfResults": null,
                    "OverrideSearchType": null,
                    "RerankingConfiguration": null,
                    "$type": "KnowledgeBaseVectorSearchConfiguration"
                },
                "$type": "KnowledgeBaseRetrievalConfiguration"
            },
            "$type": "KnowledgeBaseRetrieveAndGenerateConfiguration"
        },
        "Type": {
            "Value": "KNOWLEDGE_BASE",
            "$type": "RetrieveAndGenerateType"
        },
        "$type": "RetrieveAndGenerateConfiguration"
    },
    "SessionConfiguration": null,
    "SessionId": null,
    "$type": "RetrieveAndGenerateRequest"
}

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Document class needs to serializable and should pass the Value defined into the payload.

Current Behavior

Document object is not serializable.

Reproduction Steps

In the details above.

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

4.0.0-Preview5

Targeted .NET Platform

.Net 8.0

Operating System and version

Lambda

@phspies phspies added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 6, 2025
@ashishdhingra ashishdhingra added module/sdk-generated needs-reproduction This issue needs reproduction. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Mar 6, 2025
@ashishdhingra ashishdhingra self-assigned this Mar 6, 2025
@phspies
Copy link
Author

phspies commented Mar 6, 2025

Downgraded to v3.7.421.5 and it still persists.

@ashishdhingra
Copy link
Contributor

@phspies Good afternoon. Could you please share self-contained code to reproduce the issue? I notice that you are using Document class from Amazon.Runtime.Documents namespace. Are you using the correct type?

@phspies
Copy link
Author

phspies commented Mar 6, 2025

Image

That is what the FilterAttribute class is expecting yes. Is there another namespace I need to use here?

@ashishdhingra
Copy link
Contributor

That is what the FilterAttribute class is expecting yes. Is there another namespace I need to use here?

@phspies Good morning. I tried testing the below code in a Console application and stepped into RetrieveAndGenerateRequestMarshaller while debugging via Visual Studio:

using Amazon.BedrockAgentRuntime;
using Amazon.BedrockAgentRuntime.Model;

var client = new AmazonBedrockAgentRuntimeClient();
var retrieveAndGenerateRequest = new RetrieveAndGenerateRequest()
{
    Input = new RetrieveAndGenerateInput()
    {
        Text = "what is the diagrams about"
    },
    RetrieveAndGenerateConfiguration = new RetrieveAndGenerateConfiguration()
    {
        Type = RetrieveAndGenerateType.KNOWLEDGE_BASE,
         KnowledgeBaseConfiguration = new KnowledgeBaseRetrieveAndGenerateConfiguration()
         {
            KnowledgeBaseId = "",
            ModelArn = "",
            RetrievalConfiguration = new KnowledgeBaseRetrievalConfiguration()
            {
                VectorSearchConfiguration = new KnowledgeBaseVectorSearchConfiguration()
                {
                    Filter = new RetrievalFilter()
                    {
                        AndAll = new List<RetrievalFilter>()
                        {
                            new RetrievalFilter()
                            {
                                Equals = new FilterAttribute()
                                {
                                    Key = "TeamId",
                                    Value = new Amazon.Runtime.Documents.Document("TestTeamId")
                                }
                            },
                            new RetrievalFilter()
                            {
                                Equals = new FilterAttribute()
                                {
                                    Key = "MeetingId",
                                    Value = new Amazon.Runtime.Documents.Document("TestMeetingId")
                                }
                            }
                        }
                    }
                }
            }
         }
    }
};

var response = await client.RetrieveAndGenerateAsync(retrieveAndGenerateRequest);
Console.Read();

Inspecting the value of request JSON generated here, it had the below contents:

{
  "input": {
    "text": "what is the diagrams about"
  },
  "retrieveAndGenerateConfiguration": {
    "knowledgeBaseConfiguration": {
      "knowledgeBaseId": "",
      "modelArn": "",
      "retrievalConfiguration": {
        "vectorSearchConfiguration": {
          "filter": {
            "andAll": [
              {
                "equals": {
                  "key": "TeamId",
                  "value": "TestTeamId"
                }
              },
              {
                "equals": {
                  "key": "MeetingId",
                  "value": "TestMeetingId"
                }
              }
            ]
          }
        }
      }
    },
    "type": "KNOWLEDGE_BASE"
  }
}

Could you please share the self-contained reproducible code as a Lambda project that we could use to troubleshoot the issue? Most likely it is a serializer issue.

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/sdk-generated needs-reproduction This issue needs reproduction. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants