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

Ordering of input files nondeterministic, which can assign incorrect doc id, metadata #3

Open
dimroc opened this issue Sep 5, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@dimroc
Copy link

dimroc commented Sep 5, 2024

for i, item in enumerate(list(input_path.iterdir())): can return the files in all sorts of ordering styles. I'm not even sure what it is on my local, but it isn't lexical. What ordering are you expecting?

As a result, we don't know what order to pass in the doc_ids and metadata. Let's either come up with predictable ordering or map filenames to ids/metadata so it isn't left to mismapping 0...N indices.

I have some bandwidth, so once we have a direction, I can implement it if you'd like.

Snippet:

byaldi/byaldi/colpali.py

Lines 278 to 289 in 427a859

items = list(input_path.iterdir())
if doc_ids is not None and len(doc_ids) != len(items):
raise ValueError(
f"Number of doc_ids ({len(doc_ids)}) does not match number of documents ({len(items)})"
)
if metadata is not None and len(metadata) != len(items):
raise ValueError(
f"Number of metadata entries ({len(metadata)}) does not match number of documents ({len(items)})"
)
for i, item in enumerate(items):
print(f"Indexing file: {item}")
doc_id = doc_ids[i] if doc_ids else self.highest_doc_id + 1

@dimroc dimroc changed the title Ordering of input files nondeterministic, which can assign incorrect of doc id, metadata Ordering of input files nondeterministic, which can assign incorrect doc id, metadata Sep 5, 2024
@bclavie
Copy link
Contributor

bclavie commented Sep 6, 2024

Hey, thank you for raising, well spotted!

This has actually been on my to-do in some form, and the way I've been thinking about handling this is:

  • Allow doc ids to be strings (requiring a mapping update, but that's fine) for extra flexibility
  • If passing a folder, require the user passed doc ids and metadata to be a dictionary, in the format {filename: XXX}.
  • Should the user not pass doc_ids, the document IDs would just default to the file names.

I'm not sure I'll have the bandwidth to do it today (I'd love to though), so if you're interested in taking this on and think you can do it quickly, you're more than welcome!

@bclavie
Copy link
Contributor

bclavie commented Sep 6, 2024

In the meantime, I'm releasing 0.0.2, which among other minor updates, makes index(), add_to_index() and the newly added get_doc_ids_to_file_names() return a dict mapping {doc_id: filename}, so it's easy to pass the right context to your LLM, though it doesn't fix the metadata issue.

@bclavie bclavie added the enhancement New feature or request label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants