AlexAltea / milli-py

Python bindings for Milli, the embeddable Rust-based search engine powering Meilisearch
MIT License
123 stars 2 forks source link

Expose indexDocumentsMethod in Index.add_documents to update documents #3

Closed mjordan closed 1 year ago

mjordan commented 1 year ago

Will there be an update_documents method or will replacing with add_documents be the preferred way?

AlexAltea commented 1 year ago

I've tried to make the API resemble the original as much as possible (as much as Rust lifetimes allow).

Milli only exposes add_documents, where the default behavior is replacing existing documents with identical IDs with a newer version, see https://github.com/meilisearch/milli/blob/758b4acea7cecd689650bee65949b49cf09ddaa3/milli/src/update/index_documents/mod.rs#L69

Because of this, right now, you can "replace" documents but not "update" them.

In a future version, I'll expose these optional keyword arguments via:

Index.add_documents(..., update_method=IndexDocumentsMethod.ReplaceDocuments)

so that you can select IndexDocumentsMethod.ReplaceDocuments or IndexDocumentsMethod.UpdateDocuments depending on the intended behavior.

AlexAltea commented 1 year ago

This is now possible as of https://github.com/AlexAltea/milli-py/commit/7e0fb580267748270aa60324552fb689506bfd9b.

Example: https://github.com/AlexAltea/milli-py/blob/7e0fb580267748270aa60324552fb689506bfd9b/tests/test_milli_index.py#L18-L38

itsthejoker commented 1 year ago

@AlexAltea can you create a new release for PyPI? This change is not present in the current release. Thanks!