haystack-core-integrations icon indicating copy to clipboard operation
haystack-core-integrations copied to clipboard

feat(azure-ai-search): Allow full metadata field customization

Open denisw opened this issue 7 months ago • 2 comments

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 SearchField instances and are also serialized that way. This simplifies the code and also fixes the potential issues around trying to serialize type objects by name.

  • I noticed a type error that I fixed in this PR as well: the filters parameter of the _*_retrieval() methods was clearly meant to be str (judging from the Retriever code calling it), but was accidentally typed as Dict[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:.

denisw avatar Apr 28 '25 13:04 denisw

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 28 '25 13:04 CLAassistant

Sorry for keeping the build broken for so long. This is now fixed and the PR is ready for review.

denisw avatar May 13 '25 04:05 denisw

@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 avatar Jun 04 '25 12:06 Amnah199

@Amnah199 Sorry for not getting back to this. Great to hear that an updated version has been merged now, thanks a lot!

denisw avatar Jun 04 '25 18:06 denisw