Title: HnswDocumentIndex treats document IDs as string, they can be str, int, ID · Issue #1850 · docarray/docarray · GitHub
Open Graph Title: HnswDocumentIndex treats document IDs as string, they can be str, int, ID · Issue #1850 · docarray/docarray
X Title: HnswDocumentIndex treats document IDs as string, they can be str, int, ID · Issue #1850 · docarray/docarray
Description: Initial Checks I have read and followed the docs and still think this is a bug Description I noticed this behavior when I wanted to access multiple documents in the index: @requests(on='/find') def find(self, docs: DocList[QuoteFile], **...
Open Graph Description: Initial Checks I have read and followed the docs and still think this is a bug Description I noticed this behavior when I wanted to access multiple documents in the index: @requests(on='/find') def...
X Description: Initial Checks I have read and followed the docs and still think this is a bug Description I noticed this behavior when I wanted to access multiple documents in the index: @requests(on='/find...
Opengraph URL: https://github.com/docarray/docarray/issues/1850
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"HnswDocumentIndex treats document IDs as string, they can be str, int, ID","articleBody":"### Initial Checks\n\n- [X] I have read and followed [the docs](https://docs.docarray.org/) and still think this is a bug\n\n### Description\n\nI noticed this behavior when I wanted to access multiple documents in the index:\r\n\r\n```python\r\n@requests(on='/find')\r\n def find(self, docs: DocList[QuoteFile], **_) -\u003e DocList[QuoteFile]:\r\n return self._cache_di[docs.id]\r\n```\r\n\r\nAnd when I issue POST /find with body `{\"data\":[{\"id\":\"300055\"}]}`, this code yields:\r\n```bash\r\n \"/Users/oytuntez/motaword/jina-documents/venv/lib/py… \r\n line 544, in _get_docs_sqlite_doc_id \r\n hashed_ids = tuple(self._to_hashed_id(id_) for \r\n id_ in doc_ids) \r\n File \r\n \"/Users/oytuntez/motaword/jina-documents/venv/lib/py… \r\n line 544, in \u003cgenexpr\u003e \r\n hashed_ids = tuple(self._to_hashed_id(id_) for \r\n id_ in doc_ids) \r\n File \r\n \"/Users/oytuntez/motaword/jina-documents/venv/lib/py… \r\n line 445, in _to_hashed_id \r\n return \r\n int(hashlib.sha256(doc_id.encode('utf-8')).hexdigest… \r\n 16) % 10**18 \r\n AttributeError: 'int' object has no attribute \r\n 'encode' \r\n```\r\n\r\nUpon investigation, I saw that most of `HnswDocumentIndex` treats IDs as `str`. However, it is my understanding that IDs can be `int`, see this type definition:\r\n\r\n```python\r\nclass ID(str, AbstractType):\r\n \"\"\"\r\n Represent an unique ID\r\n \"\"\"\r\n\r\n @classmethod\r\n def _docarray_validate(\r\n cls: Type[T],\r\n value: Union[str, int, UUID],\r\n...\r\n```\r\n\r\nI think ID values should be cast to `str` if necessary (it would be in `_to_hashed_id` case).\n\n### Example Code\n\n_No response_\n\n### Python, DocArray \u0026 OS Version\n\n```Text\nPython 3.8.12\r\ndocarray==0.40.0\n```\n\n\n### Affected Components\n\n- [X] [Vector Database / Index](https://docs.docarray.org/user_guide/storing/docindex/)\n- [ ] [Representing](https://docs.docarray.org/user_guide/representing/first_step)\n- [ ] [Sending](https://docs.docarray.org/user_guide/sending/first_step/)\n- [X] [storing](https://docs.docarray.org/user_guide/storing/first_step/)\n- [X] [multi modal data type](https://docs.docarray.org/data_types/first_steps/)","author":{"url":"https://github.com/oytuntez","@type":"Person","name":"oytuntez"},"datePublished":"2024-02-07T23:23:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/1850/docarray/issues/1850"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3f5c8830-5f8b-727e-dea3-de586c519617 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9AE0:36E6DC:10B3C5E:16A3EE7:6964A239 |
| html-safe-nonce | 524225da262e1f04af591d1de640912e3bec5cf0f6e61b2d6d1e2c4a09cc6f3c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUUwOjM2RTZEQzoxMEIzQzVFOjE2QTNFRTc6Njk2NEEyMzkiLCJ2aXNpdG9yX2lkIjoiNDU4MDc4Njc3MTMzNzcxNjI4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ceeb365ac4f2c55d60218b9b89b68653229515588cfd9c9c3c8fafb615eda279 |
| hovercard-subject-tag | issue:2124076914 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/docarray/docarray/1850/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7f12d2a1ed63567ea6f32e35658afe50789818844c845a6f652e70d12f8bfbbd/docarray/docarray/issues/1850 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7f12d2a1ed63567ea6f32e35658afe50789818844c845a6f652e70d12f8bfbbd/docarray/docarray/issues/1850 |
| og:image:alt | Initial Checks I have read and followed the docs and still think this is a bug Description I noticed this behavior when I wanted to access multiple documents in the index: @requests(on='/find') def... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | oytuntez |
| hostname | github.com |
| expected-hostname | github.com |
| None | baa7d9900fdf7b27d604f36887af878d569cfbdcf97126832a5f4f0caf0c6ba5 |
| turbo-cache-control | no-preview |
| go-import | github.com/docarray/docarray git https://github.com/docarray/docarray.git |
| octolytics-dimension-user_id | 117445116 |
| octolytics-dimension-user_login | docarray |
| octolytics-dimension-repository_id | 438303578 |
| octolytics-dimension-repository_nwo | docarray/docarray |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 438303578 |
| octolytics-dimension-repository_network_root_nwo | docarray/docarray |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 842eff1d11f899d02b6b3b98fa3ea4860e64b34e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width