Type Error Langchain auto converting string to date.timestamp in Pinecone similarity search when Document pagecontent value is a string that "could" be a date ex: 21070926
Labels: name: auto:bug

### System Info

langchain==0.0.206 ; python_version >= "3.11" and python_version < "4.0"
langchainplus-sdk==0.0.16 ; python_version >= "3.11" and python_version < "4.0"


### Who can help?

@hwaking @agola11 Hey Guys! The pinecone wrapper is doing a weird auto-type conversion and its thinking my string ID values are dates in this part of the code:                


### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Have a string value set as your Pinecone Document.pagecontent that could be misinterpreted as a date ex: 21070809

Problem function:     

def similarity_search_with_score(
        self,
        query: str,
        k: int = 4,
        filter: Optional[dict] = None,
        namespace: Optional[str] = None,
    ) -> List[Tuple[Document, float]]:
        """Return pinecone documents most similar to query, along with scores.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter: Dictionary of argument(s) to filter on metadata
            namespace: Namespace to search in. Default will search in '' namespace.

        Returns:
            List of Documents most similar to the query and score for each
        """
        if namespace is None:
            namespace = self._namespace
        query_obj = self._embedding_function(query)
        docs = []
        results = self._index.query(
            [query_obj],
            top_k=k,
            include_metadata=True,
            namespace=namespace,
            filter=filter,
        )
        for res in results["matches"]:
            metadata = res["metadata"]
            if self._text_key in metadata:
                text = metadata.pop(self._text_key)
                score = res["score"]
                # if (type(text) != str):    <-------------------------- I added this code to convert it back to string
                #     text = text.strftime("%Y%m%d") <------------- If you can just recast to string the problem will resolve
                docs.append((Document(page_content=text, metadata=metadata), score))
            else:
                logger.warning(
                    f"Found document with no `{self._text_key}` key. Skipping."
                )
        return docs



Stack: [langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
[langchain] [2023-07-12 17:43:08]     result = await app(  # type: ignore[func-returns-value]
[langchain] [2023-07-12 17:43:08]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
[langchain] [2023-07-12 17:43:08]     return await self.app(scope, receive, send)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/fastapi/applications.py", line 282, in __call__
[langchain] [2023-07-12 17:43:08]     await super().__call__(scope, receive, send)
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 348, in _sentry_patched_asgi_app
[langchain] [2023-07-12 17:43:08]     return await middleware(scope, receive, send)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py", line 141, in _run_asgi3
[langchain] [2023-07-12 17:43:08]     return await self._run_app(scope, lambda: self.app(scope, receive, send))
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py", line 190, in _run_app
[langchain] [2023-07-12 17:43:08]     raise exc from None
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py", line 185, in _run_app
[langchain] [2023-07-12 17:43:08]     return await callback()
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/starlette/applications.py", line 122, in __call__
[langchain] [2023-07-12 17:43:08]     await self.middleware_stack(scope, receive, send)
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 143, in _create_span_call
[langchain] [2023-07-12 17:43:08]     return await old_call(app, scope, new_receive, new_send, **kwargs)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in __call__
[langchain] [2023-07-12 17:43:08]     raise exc
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__
[langchain] [2023-07-12 17:43:08]     await self.app(scope, receive, _send)
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 242, in _sentry_exceptionmiddleware_call
[langchain] [2023-07-12 17:43:08]     await old_call(self, scope, receive, send)
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 143, in _create_span_call
[langchain] [2023-07-12 17:43:08]     return await old_call(app, scope, new_receive, new_send, **kwargs)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
[langchain] [2023-07-12 17:43:08]     raise exc
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
[langchain] [2023-07-12 17:43:08]     await self.app(scope, receive, sender)
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 143, in _create_span_call
[langchain] [2023-07-12 17:43:08]     return await old_call(app, scope, new_receive, new_send, **kwargs)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
[langchain] [2023-07-12 17:43:08]     raise e
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
[langchain] [2023-07-12 17:43:08]     await self.app(scope, receive, send)
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/starlette/routing.py", line 718, in __call__
[langchain] [2023-07-12 17:43:08]     await route.handle(scope, receive, send)
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/starlette/routing.py", line 276, in handle
[langchain] [2023-07-12 17:43:08]     await self.app(scope, receive, send)
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/starlette/routing.py", line 66, in app
[langchain] [2023-07-12 17:43:08]     response = await func(request)
[langchain] [2023-07-12 17:43:08]                ^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/sentry_sdk/integrations/fastapi.py", line 131, in _sentry_app
[langchain] [2023-07-12 17:43:08]     return await old_app(*args, **kwargs)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/fastapi/routing.py", line 241, in app
[langchain] [2023-07-12 17:43:08]     raw_response = await run_endpoint_function(
[langchain] [2023-07-12 17:43:08]                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/fastapi/routing.py", line 167, in run_endpoint_function
[langchain] [2023-07-12 17:43:08]     return await dependant.call(**values)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/search.py", line 528, in ask_question_0_gateway
[langchain] [2023-07-12 17:43:08]     return await ask_question_0(question, user)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/search.py", line 282, in ask_question_0
[langchain] [2023-07-12 17:43:08]     response = await pinecone_search(question, metadata_filter)
[langchain] [2023-07-12 17:43:08]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/search.py", line 274, in pinecone_search
[langchain] [2023-07-12 17:43:08]     return pine.similarity_search_with_score(query=question, k=k, filter=filter)
[langchain] [2023-07-12 17:43:08]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/langchain/vectorstores/pinecone.py", line 132, in similarity_search_with_score
[langchain] [2023-07-12 17:43:08]     docs.append((Document(page_content=text, metadata=metadata), score))
[langchain] [2023-07-12 17:43:08]                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[langchain] [2023-07-12 17:43:08]   File "/workspace/.heroku/python/lib/python3.11/site-packages/langchain/load/serializable.py", line 64, in __init__
[langchain] [2023-07-12 17:43:08]     super().__init__(**kwargs)
[langchain] [2023-07-12 17:43:08]   File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
[langchain] [2023-07-12 17:43:08]     raise validation_error
[langchain] [2023-07-12 17:43:08] pydantic.error_wrappers.ValidationError: 1 validation error for Document
[langchain] [2023-07-12 17:43:08] page_content
[langchain] [2023-07-12 17:43:08]   str type expected (type=type_error.str)

### Expected behavior

I would expect my data from Pinecone to comeback to my API exactly how I put it there. Remove the auto-conversion or implement a strict string type casting to ensure no auto-typing.