Невозможно добавить данные в ComplexField с помощью Python SDK для поиска Azure AI.Python

Программы на Python
Anonymous
Невозможно добавить данные в ComplexField с помощью Python SDK для поиска Azure AI.

Сообщение Anonymous »

Я хочу загрузить полезные данные с вложенным словарем в индекс поиска Azure AI. Я использую ComplexField в индексе для вложенного словаря в моей полезной нагрузке. Вложенный словарь не распознается индексом, и я получаю нулевую ошибку. Вот мой код:

Код: Выделить всё

    ComplexField,
CorsOptions,
SearchIndex,
ScoringProfile,
SearchFieldDataType,
SimpleField,
SearchableField,
)

request_example = {

"id": "1",
"text": "bla",
"payload": {
"processId": "00665",
"color": "green"
}

}

# Create a search index
index_client = SearchIndexClient(endpoint=service_endpoint, credential=credential)
fields = [
SimpleField(name="id", type=SearchFieldDataType.String, key=True, sortable=True, filterable=True, facetable=True),
SearchableField(name="text", type=SearchFieldDataType.String),
ComplexField(
name="payload",
fields=[
SimpleField(name="processId", type=SearchFieldDataType.String),
SimpleField(name="color", type=SearchFieldDataType.String),
],
collection=True,
)
]

# Configure the vector search configuration
vector_search = VectorSearch(
algorithms=[
HnswAlgorithmConfiguration(
name="myHnsw",
kind=VectorSearchAlgorithmKind.HNSW,
parameters=HnswParameters(
m=4,
ef_construction=400,
ef_search=500,
metric=VectorSearchAlgorithmMetric.COSINE,
)
),
],
profiles=[
VectorSearchProfile(
name="myHnswProfile",
algorithm_configuration_name="myHnsw",
),
],
)

semantic_config = SemanticConfiguration(
name="my-semantic-config",
prioritized_fields=SemanticPrioritizedFields(
# title_field=SemanticField(field_name="title"),
# keywords_fields=[SemanticField(field_name="color")],
content_fields=[SemanticField(field_name="text")]
)
)

# Create the semantic settings with the configuration
semantic_search = SemanticSearch(configurations=[semantic_config])
cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
from typing import List
scoring_profiles: List[ScoringProfile] = []
# Create the search index with the semantic settings
index = SearchIndex(name="complex_field_test", fields=fields,
vector_search=vector_search, semantic_search=semantic_search,scoring_profiles=scoring_profiles, cors_options=cors_options)
result = index_client.create_or_update_index(index)
print(f'{result.name} created')

# Upload some documents to the index
search_client = SearchClient(endpoint=service_endpoint, index_name="complex_field_test", credential=credential)
result = search_client.upload_documents([request_example])
print(f"Uploaded {len(documents)} documents")
И получаю ошибку:

Код: Выделить всё

The request is invalid. Details: A null value was found for the property named 'payload', which has the expected type 'Collection(search.complex.payload)[Nullable=False]'. The expected type 'Collection(search.complex.payload)[Nullable=False]' does not allow null values.
Итак, насколько я понимаю, вложенный словарь «полезная нагрузка» не распознается и выглядит пустым, хотя подполя зарегистрированы в индексе и не имеют нулевых значений. . Можете ли вы помочь мне с этой проблемой? Как добавить данные в ComplexField?

Подробнее здесь: https://stackoverflow.com/questions/777 ... -ai-search

Вернуться в «Python»