philippgille / chromem-go

Embeddable vector database for Go with Chroma-like interface and zero third-party dependencies. In-memory with optional persistence.
Mozilla Public License 2.0
283 stars 20 forks source link

feat: WhereDocument filter with $and, $or, $contains and $not_contains filters #96

Open iwilltry42 opened 2 months ago

iwilltry42 commented 2 months ago

Top-Level WhereDocument structs are ANDed. A WhereDocument can be a singular operator like $contains or $not_contains, which require a Value to be set. $or and $and require nested WhereDocuments

I'm sure this could be done without a struct and using some map[string]any and reflect logic, but this feels cleaner, though breaking.

Let me know what you think!

iwilltry42 commented 2 months ago

Happy to surprise you 😅

I actually would vote against using a JSON string as a function parameter - I feel like accepting such is more on the user interface's side, e.g. in a CLI or whatever UI. As a library/module I think it should use proper types. Though we could provide a QueryJSON (I'm bad at naming) func that implements your suggestion.

But that's all up to you :)

FWIW I'm not sure about the Value and WhereDocuments fields - we could use any and accept either there to reduce it to a single field. That would be more abstract.

philippgille commented 2 months ago

Sorry for the late response! The breaking change was holding me back from merging because all other changes since the last release were without breaking changes. And for releasing a version before merging, the decision regarding the Vertex options passing held me back. :grimacing:

Both are done now, so I'm open to some breaking changes (not only from this PR but also other changes) in the next release.


Having a separate method for passing the query as JSON is a good idea :+1:. I'll look into adding that as soon as this one is merged. Regarding the Value and WhereDocuments as any I'll think a bit about it.