haystack-core-integrations
haystack-core-integrations copied to clipboard
feat(azure-ai-search): Allow full metadata field customization
Related Issues
(None)
Proposed Changes:
Currently, the metadata_fields init parameter only allowed a few custom simple value types to be mapped (e.g., no nested metadata) and also hardcoded the fields to be only filterable (but not searchable or facetable, for instance).
For full flexibility, allow an Azure AI Search SearchField instance to be passed as mapping instead of a Python type. For example:
document_store = AzureAISearchDocumentStore(
index_name="my_index",
embedding_dimension=15,
metadata_fields={
"Title": SearchField(name="Title", type="Edm.String", searchable=True, filterable=True),
"Pages": SearchField(name="Pages", type="Edm.String", searchable=False, filterable=True),
},
)
How did you test it?
Updated and ran the unit + integration tests.
Notes for the reviewer
-
Internally, all metadata field mappinhs are now mapped to
SearchFieldinstances and are also serialized that way. This simplifies the code and also fixes the potential issues around trying to serializetypeobjects by name. -
I noticed a type error that I fixed in this PR as well: the
filtersparameter of the_*_retrieval()methods was clearly meant to bestr(judging from the Retriever code calling it), but was accidentally typed asDict[str, Any].
Checklist
- [x] I have read the contributors guidelines and the code of conduct
- [x] I have updated the related issue with new insights and changes
- [x] I added unit tests and updated the docstrings
- [x] I've used one of the conventional commit types for my PR title:
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.
Sorry for keeping the build broken for so long. This is now fixed and the PR is ready for review.
@denisw Thanks again for this PR. We've exported your work to this PR because we don't have edit permissions on the original one. It will be merged into the main branch.
@Amnah199 Sorry for not getting back to this. Great to hear that an updated version has been merged now, thanks a lot!