GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: nested attribute access in `find()` by anna-charlotte · Pull Request #1176 · docarray/docarray

This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Conversation

@anna-charlotte

@anna-charlotte anna-charlotte commented Feb 24, 2023

Copy link
Copy Markdown
Contributor

Goals:
allow nested attribute access in find(), which currently isn't supported yet. Nested access will be possible by '__'-separated access paths.

Example:

class InnerDoc(BaseDocument):
    title: str
    embedding: NdArray

class MyDoc(BaseDocument):
    inner: InnerDoc

query = MyDoc(inner=InnerDoc(title='query', embedding=np.random.randn((10))))
index = DocumentArray[MyDoc](
    [
        MyDoc(inner=InnerDoc(title=f'doc {i}', embedding=np.random.randn((10))))
        for i in range(10)
    ]
)

top_k, scores = find(
    index,
    query,
    embedding_field='inner__embedding',  # <----------- access path for nested access
    limit=7,
)
  • check and update documentation, if required. See guide

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot added size/s area/testing labels Feb 24, 2023
@anna-charlotte anna-charlotte mentioned this pull request Feb 24, 2023
Meta: DocArray v2 Roadmap #780
Closed
42 of 47 tasks
@github-actions github-actions Bot added area/core size/m and removed size/s labels Feb 24, 2023
@anna-charlotte
anna-charlotte marked this pull request as ready for review February 27, 2023 08:40
JohannesMessner
JohannesMessner reviewed Feb 27, 2023
View reviewed changes
Comment thread docarray/utils/find.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

samsja
samsja reviewed Feb 27, 2023
View reviewed changes
Comment thread docarray/helper.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docarray/utils/find.py Outdated
emb = embedding_type._docarray_stack(emb_list)
elif isinstance(data, DocumentArrayStacked):
emb = getattr(data, embedding_field)
emb = next(AnyDocumentArray._traverse(data, embedding_field))

@samsja samsja Feb 27, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

not sure to understand why it is next here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

samsja reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@anna-charlotte anna-charlotte Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

For DocumentArray stacked, the _traverse will yield one stacked tensor, by calling next() on it, I want to get that one tensor. I think this would be the same as calling list(AnyDocumentArray._traverse(data, embedding_field))[0].

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
JohannesMessner
JohannesMessner suggested changes Feb 27, 2023
View reviewed changes
Comment thread docarray/helper.py Outdated

def _get_field_type_by_access_path(
doc_type: Type['BaseDocument'], access_path: str
) -> Any:

@JohannesMessner JohannesMessner Feb 27, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

-> Optional[Type]?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

samsja and anna-charlotte reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@anna-charlotte anna-charlotte Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

applied!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
anna-charlotte added 12 commits February 27, 2023 14:45
anna-charlotte
test: add test for find on nested attribute
d1f651b
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
test: add test for nested attr in stacked da
e7c4178
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: nested access
5ba1857
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: mypy
7c9a617
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: field type by access path for da
5c7e862
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: clean up
e8a0003
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: move get field type by access path
8ac4827
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: imports
2cc5a21
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: apply suggestion and fix import
234cb36
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: apply suggestion from code review
95a0bd0
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: apply suggestion from code review
c520630
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte
fix: apply suggestions
8400ed4
Signed-off-by: anna-charlotte <[email protected]>
@anna-charlotte
anna-charlotte force-pushed the feat-find-nested-access branch from 68af091 to 8400ed4 Compare February 27, 2023 13:46
@github-actions

github-actions Bot commented Feb 27, 2023

Copy link
Copy Markdown

📝 Docs are deployed on https://ft-feat-find-nested-access--jina-docs.netlify.app 🎉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

samsja
samsja approved these changes Feb 27, 2023
View reviewed changes
JohannesMessner
JohannesMessner approved these changes Feb 27, 2023
View reviewed changes
@anna-charlotte
anna-charlotte merged commit 28b96fe into feat-rewrite-v2 Feb 27, 2023
@anna-charlotte
anna-charlotte deleted the feat-find-nested-access branch February 27, 2023 16:35
AsRaNi1 pushed a commit to AsRaNi1/docarray that referenced this pull request Feb 28, 2023
Charlotte Gerhaher @AsRaNi1
feat: nested attribute access in find() (docarray#1176)
9dd4e9e
* test: add test for find on nested attribute

Signed-off-by: anna-charlotte <[email protected]>

* test: add test for nested attr in stacked da

Signed-off-by: anna-charlotte <[email protected]>

* fix: nested access

Signed-off-by: anna-charlotte <[email protected]>

* fix: mypy

Signed-off-by: anna-charlotte <[email protected]>

* fix: field type by access path for da

Signed-off-by: anna-charlotte <[email protected]>

* fix: clean up

Signed-off-by: anna-charlotte <[email protected]>

* fix: move get field type by access path

Signed-off-by: anna-charlotte <[email protected]>

* fix: imports

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion and fix import

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion from code review

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion from code review

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestions

Signed-off-by: anna-charlotte <[email protected]>

---------

Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: Arnav Zutshi <[email protected]>
Jackmin801 pushed a commit that referenced this pull request Mar 2, 2023
Charlotte Gerhaher @Jackmin801
feat: nested attribute access in find() (#1176)
fafcaf3
* test: add test for find on nested attribute

Signed-off-by: anna-charlotte <[email protected]>

* test: add test for nested attr in stacked da

Signed-off-by: anna-charlotte <[email protected]>

* fix: nested access

Signed-off-by: anna-charlotte <[email protected]>

* fix: mypy

Signed-off-by: anna-charlotte <[email protected]>

* fix: field type by access path for da

Signed-off-by: anna-charlotte <[email protected]>

* fix: clean up

Signed-off-by: anna-charlotte <[email protected]>

* fix: move get field type by access path

Signed-off-by: anna-charlotte <[email protected]>

* fix: imports

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion and fix import

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion from code review

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion from code review

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestions

Signed-off-by: anna-charlotte <[email protected]>

---------

Signed-off-by: anna-charlotte <[email protected]>
Jackmin801 pushed a commit that referenced this pull request Mar 2, 2023
Charlotte Gerhaher @Jackmin801
feat: nested attribute access in find() (#1176)
1c15390
* test: add test for find on nested attribute

Signed-off-by: anna-charlotte <[email protected]>

* test: add test for nested attr in stacked da

Signed-off-by: anna-charlotte <[email protected]>

* fix: nested access

Signed-off-by: anna-charlotte <[email protected]>

* fix: mypy

Signed-off-by: anna-charlotte <[email protected]>

* fix: field type by access path for da

Signed-off-by: anna-charlotte <[email protected]>

* fix: clean up

Signed-off-by: anna-charlotte <[email protected]>

* fix: move get field type by access path

Signed-off-by: anna-charlotte <[email protected]>

* fix: imports

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion and fix import

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion from code review

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion from code review

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestions

Signed-off-by: anna-charlotte <[email protected]>

---------

Signed-off-by: anna-charlotte <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@JohannesMessner JohannesMessner JohannesMessner approved these changes
@samsja samsja samsja approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area/core area/testing size/m

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@anna-charlotte @JohannesMessner @samsja
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.