# Try filtering complex metadata from the document using langchain\_community.vectorstores.utils.filter\_complex\_metadata

**URL:** <https://community.deeplearning.ai/t/try-filtering-complex-metadata-from-the-document-using-langchain-community-vectorstores-utils-filter-complex-metadata/628474>\
**Category:** Preprocessing Unstructured Data 4 LLM Applications\
**Created:** [May 16, 2024, 4:40am UTC](https://community.deeplearning.ai/t/try-filtering-complex-metadata-from-the-document-using-langchain-community-vectorstores-utils-filter-complex-metadata/628474 "2024-05-16T04:40:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrqasimasif](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mrqasimasif/32/30586_2.png) [@mrqasimasif](https://community.deeplearning.ai/u/mrqasimasif)\
**Post date:** [May 16, 2024, 4:40am UTC](https://community.deeplearning.ai/t/try-filtering-complex-metadata-from-the-document-using-langchain-community-vectorstores-utils-filter-complex-metadata/628474/1 "2024-05-16T04:40:30Z")

</div>

Hi I am running this code from the provided notebook.

documents =   
for element in elements:  
metadata = element.metadata.to\_dict()  
del metadata[“languages”]  
metadata[“source”] = metadata[“filename”]  
documents.append(Document(page\_content=element.text, metadata=metadata))

embeddings = OpenAIEmbeddings()  
vectorstore = Chroma.from\_documents(documents, embeddings)

Running the vectorstore cell gives out the following error,  
I am unsure what will be the accurate solution to it.

Error:  
ValueError: Expected metadata value to be a str, int, float or bool, got [{‘x’: 0, ‘y’: 0, ‘w’: 1, ‘h’: 1, ‘content’: ‘NAVER CLOVA’}, {‘x’: 1, ‘y’: 0, ‘w’: 1, ‘h’: 1, ‘content’: ‘2NAVER Search’}, {‘x’: 2, ‘y’: 0, ‘w’: 1, ‘h’: 1, ‘content’: ‘3SNAVER AI Lal’}] which is a \<class ‘list’\>

Try filtering complex metadata from the document using langchain\_community.vectorstores.utils.filter\_complex\_metadata.

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [May 17, 2024, 1:39am UTC](https://community.deeplearning.ai/t/try-filtering-complex-metadata-from-the-document-using-langchain-community-vectorstores-utils-filter-complex-metadata/628474/2 "2024-05-17T01:39:40Z")

</div>

Are you really using all the necessary files for your metadata yo be as provided by the course as the course mentions issue being on how you recalled your metadata.

---

<div class="post-metadata">

**Author:** ![pkoloveas](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pkoloveas](https://community.deeplearning.ai/u/pkoloveas)\
**Post date:** [May 21, 2024, 9:02am UTC](https://community.deeplearning.ai/t/try-filtering-complex-metadata-from-the-document-using-langchain-community-vectorstores-utils-filter-complex-metadata/628474/3 "2024-05-21T09:02:09Z")

</div>

I ran into the same issue, which I solved like this:

First, import the function mentioned in the error:

```auto
from langchain_community.vectorstores.utils import filter_complex_metadata

```

Then change this line:

```auto
vectorstore = Chroma.from_documents(documents, embeddings)

```

to this:

```auto
vectorstore = Chroma.from_documents(filter_complex_metadata(documents), embeddings)

```

---

<div class="post-metadata">

**Author:** ![pbhadani](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@pbhadani](https://community.deeplearning.ai/u/pbhadani)\
**Post date:** [May 22, 2024, 9:05pm UTC](https://community.deeplearning.ai/t/try-filtering-complex-metadata-from-the-document-using-langchain-community-vectorstores-utils-filter-complex-metadata/628474/4 "2024-05-22T21:05:49Z")

</div>

thanks for sharing on how to wrap this up with “filter\_complex\_metadata”.  
But now how to use this as filter option in vector\_store.as\_retriever(‘filter’: {‘source\_name’:ABC}}).  
Source\_name is a list here.

---

<div class="post-metadata">

**Author:** ![rdyson](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rdyson/32/88744_2.png) [@rdyson](https://community.deeplearning.ai/u/rdyson)\
**Post date:** [May 28, 2024, 1:12pm UTC](https://community.deeplearning.ai/t/try-filtering-complex-metadata-from-the-document-using-langchain-community-vectorstores-utils-filter-complex-metadata/628474/5 "2024-05-28T13:12:10Z")

</div>

Thanks! This worked for me using the hosted notebook.

---

<div class="post-metadata">

**Author:** ![jie2](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jie2](https://community.deeplearning.ai/u/jie2)\
**Post date:** [December 3, 2024, 8:03am UTC](https://community.deeplearning.ai/t/try-filtering-complex-metadata-from-the-document-using-langchain-community-vectorstores-utils-filter-complex-metadata/628474/6 "2024-12-03T08:03:38Z")

</div>

oh! its so good! thanks your solution!
