Skip to content

fix: eliminate variable shadowing in get_embedding and add list key support (Fixes #37) - #39

Open
rtmalikian wants to merge 1 commit into
jdagdelen:mainfrom
rtmalikian:fix/issue-37-key-shadowing
Open

fix: eliminate variable shadowing in get_embedding and add list key support (Fixes #37)#39
rtmalikian wants to merge 1 commit into
jdagdelen:mainfrom
rtmalikian:fix/issue-37-key-shadowing

Conversation

@rtmalikian

Copy link
Copy Markdown

Fixes #37

Problem

get_embedding() has a variable shadowing bug: the loop for key in key_chain overwrites the function parameter key. While Python's loop semantics prevent a crash in most cases, this makes the code fragile and hard to maintain. Additionally, the key=None path was missing newline stripping that the key=str path had, causing inconsistent text cleaning.

Solution

Three changes to hyperdb/hyperdb.py:

  1. Eliminate variable shadowing: Rename loop variable from key to k and use a value accumulator to traverse nested keys, keeping the original key parameter intact
  2. Add list key support: When key is a list (e.g., key=["name", "city"]), extract those specific fields for concatenation — addresses the issue's concern about key type handling
  3. Fix inconsistent newline stripping: Apply replace("\n", " ") in the key=None path, matching the behavior of the key=str path

Verification

PASS: nested key extraction
PASS: list key extraction
PASS: None key extraction
PASS: newline stripping in None-key path
PASS: deeply nested key
ALL TESTS PASSED

Contact

About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.

📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a


Disclosure: This code was developed with assistance from mimo-v2.5-pro (Xiaomi) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.

…upport

Fixes jdagdelen#37

- Rename loop variable from  to  and use  accumulator
  to avoid shadowing the function parameter when traversing nested keys
- Add support for list keys (e.g., key=['name', 'city']) for selective
  field concatenation
- Add missing newline stripping in the key=None path (was only applied
  in the str-key path, causing inconsistency)
- Add comprehensive tests for all key extraction paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concatenation of text might cause mismatch of vectors and documents

1 participant