mirror of
https://github.com/hwchase17/langchain
synced 2024-11-04 06:00:26 +00:00
AzureSearch Vector Store: Moving the usage of additional_fields into context of it's definition (bug fix from python error) (#8551)
Description: Using Azure Cognitive Search as a VectorStore. Calling the `add_texts` method throws an error if there is no metadata property specified. The `additional_fields` field is set in an `if` statement and then is used later outside the if statement. This PR just moves the declaration of `additional_fields` below and puts the usage of it in context. Issue: https://github.com/langchain-ai/langchain/issues/8544 Tagging @rlancemartin, @eyurtsev as this is related to Vector stores. `make format`, `make lint`, `make spellcheck`, and `make test` have been run
This commit is contained in:
parent
8d2344db43
commit
8061994c61
@ -269,12 +269,6 @@ class AzureSearch(VectorStore):
|
||||
metadata = metadatas[i] if metadatas else {}
|
||||
# Add data to index
|
||||
# Additional metadata to fields mapping
|
||||
if metadata:
|
||||
additional_fields = {
|
||||
k: v
|
||||
for k, v in metadata.items()
|
||||
if k in [x.name for x in self.fields]
|
||||
}
|
||||
doc = {
|
||||
"@search.action": "upload",
|
||||
FIELDS_ID: key,
|
||||
@ -284,6 +278,12 @@ class AzureSearch(VectorStore):
|
||||
).tolist(),
|
||||
FIELDS_METADATA: json.dumps(metadata),
|
||||
}
|
||||
if metadata:
|
||||
additional_fields = {
|
||||
k: v
|
||||
for k, v in metadata.items()
|
||||
if k in [x.name for x in self.fields]
|
||||
}
|
||||
doc.update(additional_fields)
|
||||
data.append(doc)
|
||||
ids.append(key)
|
||||
|
Loading…
Reference in New Issue
Block a user