Skip to content

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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

denisw
Copy link

@denisw denisw commented Apr 28, 2025

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

@denisw denisw requested a review from a team as a code owner April 28, 2025 13:44
@denisw denisw requested review from vblagoje and removed request for a team April 28, 2025 13:44
@CLAassistant
Copy link

CLAassistant commented Apr 28, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added integration:azure-ai-search type:documentation Improvements or additions to documentation labels Apr 28, 2025
So far, 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.
@denisw denisw force-pushed the feature/ai-search-custom-metadata-fields branch from 2751a2a to ba0e6ac Compare April 29, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration:azure-ai-search type:documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants