azure-cognitive-searchopenaiembeddingsvector-search

Cannot convert the literal '0.0040753875' to the expected type 'Edm.String


I am getting error when I try to upload a json document with embedding vector in an index in Azure AI Search

The request is invalid. Details: Cannot convert the literal '0.0040753875' to the expected type 'Edm.String'.
Code: 
Message: The request is invalid. Details: Cannot convert the literal '0.0040753875' to the expected type 'Edm.String'.

The schema of index is

# Specify the index schema
name = index_name

fields = [
        SimpleField(name="HotelId", type=SearchFieldDataType.String, key=True),
        SearchableField(name="HotelName", type=SearchFieldDataType.String, sortable=True),
        SearchableField(name="Description", type=SearchFieldDataType.String, analyzer_name="en.lucene"),
        SearchableField(name="Description_fr", type=SearchFieldDataType.String, analyzer_name="fr.lucene"),
        SearchableField(name="Category", type=SearchFieldDataType.String, facetable=True, filterable=True, sortable=True),

        SearchableField(name="Tags", collection=True, type=SearchFieldDataType.String, facetable=True, filterable=True),

        SimpleField(name="ParkingIncluded", type=SearchFieldDataType.Boolean, facetable=True, filterable=True, sortable=True),
        SimpleField(name="LastRenovationDate", type=SearchFieldDataType.DateTimeOffset, facetable=True, filterable=True, sortable=True),
        SearchableField(name="Rating", type=SearchFieldDataType.String, facetable=True, filterable=True, sortable=True),

        ComplexField(name="Address", fields=[
            SearchableField(name="StreetAddress", type=SearchFieldDataType.String),
            SearchableField(name="City", type=SearchFieldDataType.String, facetable=True, filterable=True, sortable=True),
            SearchableField(name="StateProvince", type=SearchFieldDataType.String, facetable=True, filterable=True, sortable=True),
            SearchableField(name="PostalCode", type=SearchFieldDataType.String, facetable=True, filterable=True, sortable=True),
            SearchableField(name="Country", type=SearchFieldDataType.String, facetable=True, filterable=True, sortable=True),
        ]),
        SearchableField(name="HotelNameVector",collection=True, type=SearchFieldDataType.Single,retrievable=True,searchable=True,vector_search_dimensions=1536,vector_search_profile_name="my-vector-profile"),
        SearchableField(name="DescriptionVector",collection=True, type=SearchFieldDataType.Single,retrievable=True,searchable=True,vector_search_dimensions=1536,vector_search_profile_name="my-vector-profile"),
    ]

hnswParameters = HnswParameters(m=4,ef_construction= 400, ef_search= 500, metric= "cosine")
vectorSearchAlgorithm = HnswAlgorithmConfiguration(name = "my-hnsw-vector-config-1",parameters=hnswParameters)
vectorSearchProfile = VectorSearchProfile(name="my-vector-profile",algorithm_configuration_name="my-hnsw-vector-config-1")

semantic_config = SemanticConfiguration(
    name="my-semantic-config",
    prioritized_fields=SemanticPrioritizedFields(
        title_field=SemanticField(field_name="HotelName"),
        keywords_fields=[SemanticField(field_name="Category")],
        content_fields=[SemanticField(field_name="Description")]
    )
)
vector_search = VectorSearch(profiles = [vectorSearchProfile],algorithms=[vectorSearchAlgorithm])
semantic_search = SemanticSearch(configurations=[semantic_config])
suggester = [{'name': 'sg', 'source_fields': ['Tags', 'Address/City', 'Address/Country']}]
scoring_profiles = []

The document I am uploading is

documents = [
    {
    "@search.action": "upload",
    "HotelId": "1",
    "HotelName": "Secret Point Motel",
    "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Time's Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",

    "Description_fr": "L'hôtel est idéalement situé sur la principale artère commerciale de la ville en plein cœur de New York. A quelques minutes se trouve la place du temps et le centre historique de la ville, ainsi que d'autres lieux d'intérêt qui font de New York l'une des villes les plus attractives et cosmopolites de l'Amérique.",
    "Category": "Boutique",
    "Tags": [ "pool", "air conditioning", "concierge" ],
    "ParkingIncluded": "false",
    "LastRenovationDate": "1970-01-18T00:00:00Z",
    "Rating": "3.60",
    "Address": {
        "StreetAddress": "677 5th Ave",
        "City": "New York",
        "StateProvince": "NY",
        "PostalCode": "10022",
        "Country": "USA"
        },
    "HotelNameVector":[
                0.0040753875,
....

I am following this tutorial - https://learn.microsoft.com/en-us/azure/search/search-get-started-vector - but instead of creating a put request, I am using python library


Solution

  • IIRC SearchableField doesn't allow you to change the underlying type, it might be ignoring your input and always setting up the field as a string (or collection of strings). Try using SearchField instead for your 2 vector fields. You also might need to change how you declare it as a collection, it needs to look like this:

    SearchField(name="HotelNameVector",
        type=SearchFieldDataType.Collection(SearchFieldDataType.Single), 
        searchable=True, 
        retrievable=True,
        vector_search_dimensions=1536,
        vector_search_profile="my-vector-profile")