Skip to content
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

Issue : langchain sample fails #182

Open
surendransuri opened this issue Feb 28, 2024 · 2 comments
Open

Issue : langchain sample fails #182

surendransuri opened this issue Feb 28, 2024 · 2 comments

Comments

@surendransuri
Copy link

surendransuri commented Feb 28, 2024

I tried to replicate the notebook azure-search-vector-python-langchain-sample.ipynb to add documents to the index.
Here the schema for index created is not provided please provide the index schema creation code for this sample.

Example:
I tried to create a manual schema like below and tried to add documents

Index Schema Creation:
fields = [
SearchField(name="id", type=SearchFieldDataType.String, key=True, sortable=True, filterable=True, facetable=True, analyzer_name="keyword"),
SearchField(name="content", type=SearchFieldDataType.String, sortable=False, filterable=False, facetable=False),
SearchField(name="page_content", type=SearchFieldDataType.String, sortable=False, filterable=False, facetable=False),
ComplexField(name="metadata",
fields=[SearchField(name="source", type=SearchFieldDataType.String),
SearchField(name="page", type=SearchFieldDataType.Int32),
]
),
SearchField(name="vector", type=SearchFieldDataType.Collection(SearchFieldDataType.Single), vector_search_dimensions=1536, vector_search_profile_name="myHnswProfile"),
]

Failed in below line of code with the mentioned error:
line of code --->

results = vector_store.add_documents(documents=file_chunks)

(file_chunks structure:

[Document(page_content='title:PerksPlus.pdf, PerksPlus Health and Wellness \nReimbursement Program for \nContoso Electronics Employees' metadata={'source': 'C:/Users/Surs092/Downloads/Data\PerksPlus.pdf', 'page': 0}
]

)

Error message:
Exception Occured () The request is invalid. Details: A 'PrimitiveValue' node with non-null value was found when trying to read the value of the property 'metadata'; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected.
Code:
Message: The request is invalid. Details: A 'PrimitiveValue' node with non-null value was found when trying to read the value of the property 'metadata'; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected. for file PerksPlus.pdf
Indexed 0 chunks

Also, please provide sample code to create and add custom fields to the vector index

@mattgotteiner
Copy link
Member

Thanks, we'll try to reproduce this issue

@roflaala
Copy link

This issue got resolved for me when I made a change in site-packages\langchain_community\vectorstores\azuresearch.py file.
I changed FIELDS_METADATA: json.dumps(metadata) to FIELDS_METADATA: metadata on line 348.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants