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

Fix a bug to unflatten the doc with list of map with multiple entries correctly #1204

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

bzhangam
Copy link
Contributor

@bzhangam bzhangam commented Feb 27, 2025

Description

Fix a bug to unflatten the doc with list of map with multiple entries correctly.

Let's say we have a doc like:

{
   "test.products":[
      {
         "product_description":"product_description 1",
         "price":10
      },
      {
         "product_description":"product_description 2",
         "price":20
      }
   ]
}

If we define an ingest pipeline to create the embedding for the product_description we will try to unflatten the doc first to ensure the . in the field name will be handled properly. Before my fix the doc will be unflattened like:

{
   "test":{
      "products":[
         {
            "price":10
         },
         {
            "price":20
         }
      ]
   }
}

We lose the product_description because when we handle the map in a list we incorrectly do targetList.set(targetList.size() - 1, tempMap);. With my fix the doc will be unflattened correctly:

{
   "test":{
      "products":[
         {
            "product_description":"product_description 1",
            "price":10
         },
         {
            "product_description":"product_description 2",
            "price":20
         }
      ]
   }
}

Related Issues

There is no related issue.

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.71%. Comparing base (9cc8959) to head (8f7b230).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1204      +/-   ##
============================================
- Coverage     81.77%   81.71%   -0.06%     
+ Complexity     2512     1255    -1257     
============================================
  Files           190       95      -95     
  Lines          8564     4282    -4282     
  Branches       1436      718     -718     
============================================
- Hits           7003     3499    -3504     
+ Misses         1003      506     -497     
+ Partials        558      277     -281     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@will-hwang
Copy link
Contributor

looks good to me. signoff your commit

@heemin32
Copy link
Collaborator

heemin32 commented Feb 27, 2025

Please fix the failed DCO checks.

@martin-gaievski
Copy link
Member

few questions here:

  • what does it mean for end-user if we loose that prefix part in the flattened document?
  • what the impact of this change, which exact processors can be affected by this change? To me it looks like all inference processors and that includes both single and batch modes, is this correct?

@will-hwang
Copy link
Contributor

few questions here:

  • what does it mean for end-user if we loose that prefix part in the flattened document?
  • what the impact of this change, which exact processors can be affected by this change? To me it looks like all inference processors and that includes both single and batch modes, is this correct?

text embedding processor and sparse encoding processor would be affected by this change since they both extend from InferenceProcessor, where unflatten is used for pre-processing the ingest document.

@will-hwang
Copy link
Contributor

@bzhangam an alternative to consider is:

we could treat

{
"product_description":"product_description 1",
"price":10
}

as a single item to be pushed to stack, and and modify unflattenSingleItem. That will allow the existing logic to work as is. I'll leave it up to you to decide, as this will require additional changes

@bzhangam
Copy link
Contributor Author

few questions here:

  • what does it mean for end-user if we loose that prefix part in the flattened document?
  • what the impact of this change, which exact processors can be affected by this change? To me it looks like all inference processors and that includes both single and batch modes, is this correct?

Yeah all the inference processors are impacted by this bug. If we run into the bug the doc will lose some data and the missing data will not be stored to the source or index. The missing data is removed from the ingestDoc.

@bzhangam
Copy link
Contributor Author

bzhangam commented Feb 27, 2025

@bzhangam an alternative to consider is:

we could treat

{
"product_description":"product_description 1",
"price":10
}

as a single item to be pushed to stack, and and modify unflattenSingleItem. That will allow the existing logic to work as is. I'll leave it up to you to decide, as this will require additional changes

I think that one line fix should be good enough. I feel it should be done that way. The bug is more like a typo thing.

… correctly.

Signed-off-by: Bo Zhang <bzhangam@amazon.com>
@bzhangam bzhangam reopened this Feb 27, 2025
Copy link
Collaborator

@heemin32 heemin32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Copy link
Member

@junqiu-lei junqiu-lei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixing, LGTM.

@heemin32 heemin32 merged commit da5eebb into opensearch-project:main Feb 28, 2025
98 of 101 checks passed
@martin-gaievski martin-gaievski added the v3.0.0 v3.0.0 label Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3.0.0 v3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants