L4 - Validation Error while running response = index.query(query, llm = llm_replacement_model)

I got this validation error when I run locally

llm_replacement_model = OpenAI(temperature=0,
model=‘gpt-3.5-turbo-instruct’)

response = index.query(query,
llm = llm_replacement_model)

ValidationError: 2 validation errors for DocArrayDoc
text
Field required [type=missing, input_value={‘embedding’: [0.00331889…, -0.02122992287370924]}, input_type=dict]
For further information visit Redirecting...
metadata
Field required [type=missing, input_value={‘embedding’: [0.00331889…, -0.02122992287370924]}, input_type=dict]
For further information visit Redirecting...

1 Like

I got the same error. I tried to downgrade the docarray module to 0.21, but that didn’t fix the problem.

1 Like

I solved it, using this solution: ValidationError: 2 validation errors for DocArrayDoc returned when try to execute the RAG Search Example · Issue #14585 · langchain-ai/langchain · GitHub

!pip install pydantic==1.10.13
!pip install docarray==0.32.1
3 Likes

Hi @Swiftly7772, @Andrea_Gigli,

Are you guys running the notebook locally ?

1 Like

Yes.

1 Like

Can you post all your pip installs? I’m getting other issues. thanks

2 Likes

I’m using pyenv to help with dependencies

1 Like
pydantic==1.10.13
docarray==0.32.1
langchain==0.0.347
openai==0.27.7
tiktoken
python-dotenv
pandas

python 3.12 was not compatible with docarray so I downgraded to 3.11 which worked for me

2 Likes

I just installed the latest version of all the modules using pip install. And just downgraded the modules pydantic and docarray.

1 Like

Thanks @Swiftly7772 it worked for me as well!

1 Like

I am also getting the same error and it did not got solved even after downgrading to followings, can someone please suggest -

!pip install pydantic==1.10.13
!pip install docarray==0.32.1

Thanks in advance.

1 Like

This helps! Thanks @Swiftly7772!

1 Like

You may try “Restart and Clear Cell Outputs” before you do the pip installs

1 Like

I downgraded the following packages:
pydantic==1.10.13
docarray==0.32.1
openai==0.28.1
langchain==0.0.347

When I run the code ‘response = index.query(query)’, the above ‘validation related errors’ has resolved, but I got new error:

InvalidRequestError: The model text-davinci-003 has been deprecated, learn more here:…

How to fix the problem? Thank you guys.

The code is:

from langchain.chains import RetrievalQA # retrieval over doc
from langchain.chat_models import ChatOpenAI
from langchain.document_loaders import CSVLoader # doc loader
from langchain.vectorstores import DocArrayInMemorySearch # in memory vector store
from IPython.display import display, Markdown

file = 'OutdoorClothingCatalog_1000.csv'
loader = CSVLoader(file_path=file)

from langchain.indexes import VectorstoreIndexCreator
index = VectorstoreIndexCreator(
    vectorstore_cls=DocArrayInMemorySearch
).from_loaders([loader])
query ="Please list all your shirts with sun protection \
in a table in markdown and summarize each one."
response = index.query(query)

The full error messages is:

---------------------------------------------------------------------------
InvalidRequestError                       Traceback (most recent call last)
Cell In[7], line 1
----> 1 response = index.query(query)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/indexes/vectorstore.py:46, in VectorStoreIndexWrapper.query(self, question, llm, retriever_kwargs, **kwargs)
     42 retriever_kwargs = retriever_kwargs or {}
     43 chain = RetrievalQA.from_chain_type(
     44     llm, retriever=self.vectorstore.as_retriever(**retriever_kwargs), **kwargs
     45 )
---> 46 return chain.run(question)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/base.py:507, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
    505     if len(args) != 1:
    506         raise ValueError("`run` supports only one positional argument.")
--> 507     return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    508         _output_key
    509     ]
    511 if kwargs and not args:
    512     return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
    513         _output_key
    514     ]

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/base.py:312, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    310 except BaseException as e:
    311     run_manager.on_chain_error(e)
--> 312     raise e
    313 run_manager.on_chain_end(outputs)
    314 final_outputs: Dict[str, Any] = self.prep_outputs(
    315     inputs, outputs, return_only_outputs
    316 )

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/base.py:306, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    299 run_manager = callback_manager.on_chain_start(
    300     dumpd(self),
    301     inputs,
    302     name=run_name,
    303 )
    304 try:
    305     outputs = (
--> 306         self._call(inputs, run_manager=run_manager)
    307         if new_arg_supported
    308         else self._call(inputs)
    309     )
    310 except BaseException as e:
    311     run_manager.on_chain_error(e)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/retrieval_qa/base.py:144, in BaseRetrievalQA._call(self, inputs, run_manager)
    142 else:
    143     docs = self._get_docs(question)  # type: ignore[call-arg]
--> 144 answer = self.combine_documents_chain.run(
    145     input_documents=docs, question=question, callbacks=_run_manager.get_child()
    146 )
    148 if self.return_source_documents:
    149     return {self.output_key: answer, "source_documents": docs}

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/base.py:512, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
    507     return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    508         _output_key
    509     ]
    511 if kwargs and not args:
--> 512     return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
    513         _output_key
    514     ]
    516 if not kwargs and not args:
    517     raise ValueError(
    518         "`run` supported with either positional arguments or keyword arguments,"
    519         " but none were provided."
    520     )

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/base.py:312, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    310 except BaseException as e:
    311     run_manager.on_chain_error(e)
--> 312     raise e
    313 run_manager.on_chain_end(outputs)
    314 final_outputs: Dict[str, Any] = self.prep_outputs(
    315     inputs, outputs, return_only_outputs
    316 )

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/base.py:306, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    299 run_manager = callback_manager.on_chain_start(
    300     dumpd(self),
    301     inputs,
    302     name=run_name,
    303 )
    304 try:
    305     outputs = (
--> 306         self._call(inputs, run_manager=run_manager)
    307         if new_arg_supported
    308         else self._call(inputs)
    309     )
    310 except BaseException as e:
    311     run_manager.on_chain_error(e)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/combine_documents/base.py:123, in BaseCombineDocumentsChain._call(self, inputs, run_manager)
    121 # Other keys are assumed to be needed for LLM prediction
    122 other_keys = {k: v for k, v in inputs.items() if k != self.input_key}
--> 123 output, extra_return_dict = self.combine_docs(
    124     docs, callbacks=_run_manager.get_child(), **other_keys
    125 )
    126 extra_return_dict[self.output_key] = output
    127 return extra_return_dict

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/combine_documents/stuff.py:172, in StuffDocumentsChain.combine_docs(self, docs, callbacks, **kwargs)
    170 inputs = self._get_inputs(docs, **kwargs)
    171 # Call predict on the LLM.
--> 172 return self.llm_chain.predict(callbacks=callbacks, **inputs), {}

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/llm.py:293, in LLMChain.predict(self, callbacks, **kwargs)
    278 def predict(self, callbacks: Callbacks = None, **kwargs: Any) -> str:
    279     """Format prompt with kwargs and pass to LLM.
    280 
    281     Args:
   (...)
    291             completion = llm.predict(adjective="funny")
    292     """
--> 293     return self(kwargs, callbacks=callbacks)[self.output_key]

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/base.py:312, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    310 except BaseException as e:
    311     run_manager.on_chain_error(e)
--> 312     raise e
    313 run_manager.on_chain_end(outputs)
    314 final_outputs: Dict[str, Any] = self.prep_outputs(
    315     inputs, outputs, return_only_outputs
    316 )

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/base.py:306, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    299 run_manager = callback_manager.on_chain_start(
    300     dumpd(self),
    301     inputs,
    302     name=run_name,
    303 )
    304 try:
    305     outputs = (
--> 306         self._call(inputs, run_manager=run_manager)
    307         if new_arg_supported
    308         else self._call(inputs)
    309     )
    310 except BaseException as e:
    311     run_manager.on_chain_error(e)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/llm.py:103, in LLMChain._call(self, inputs, run_manager)
     98 def _call(
     99     self,
    100     inputs: Dict[str, Any],
    101     run_manager: Optional[CallbackManagerForChainRun] = None,
    102 ) -> Dict[str, str]:
--> 103     response = self.generate([inputs], run_manager=run_manager)
    104     return self.create_outputs(response)[0]

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/chains/llm.py:115, in LLMChain.generate(self, input_list, run_manager)
    113 callbacks = run_manager.get_child() if run_manager else None
    114 if isinstance(self.llm, BaseLanguageModel):
--> 115     return self.llm.generate_prompt(
    116         prompts,
    117         stop,
    118         callbacks=callbacks,
    119         **self.llm_kwargs,
    120     )
    121 else:
    122     results = self.llm.bind(stop=stop, **self.llm_kwargs).batch(
    123         cast(List, prompts), {"callbacks": callbacks}
    124     )

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain_core/language_models/llms.py:516, in BaseLLM.generate_prompt(self, prompts, stop, callbacks, **kwargs)
    508 def generate_prompt(
    509     self,
    510     prompts: List[PromptValue],
   (...)
    513     **kwargs: Any,
    514 ) -> LLMResult:
    515     prompt_strings = [p.to_string() for p in prompts]
--> 516     return self.generate(prompt_strings, stop=stop, callbacks=callbacks, **kwargs)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain_core/language_models/llms.py:666, in BaseLLM.generate(self, prompts, stop, callbacks, tags, metadata, run_name, **kwargs)
    650         raise ValueError(
    651             "Asked to cache, but no cache found at `langchain.cache`."
    652         )
    653     run_managers = [
    654         callback_manager.on_llm_start(
    655             dumpd(self),
   (...)
    664         )
    665     ]
--> 666     output = self._generate_helper(
    667         prompts, stop, run_managers, bool(new_arg_supported), **kwargs
    668     )
    669     return output
    670 if len(missing_prompts) > 0:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain_core/language_models/llms.py:553, in BaseLLM._generate_helper(self, prompts, stop, run_managers, new_arg_supported, **kwargs)
    551     for run_manager in run_managers:
    552         run_manager.on_llm_error(e, response=LLMResult(generations=[]))
--> 553     raise e
    554 flattened_outputs = output.flatten()
    555 for manager, flattened_output in zip(run_managers, flattened_outputs):

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain_core/language_models/llms.py:540, in BaseLLM._generate_helper(self, prompts, stop, run_managers, new_arg_supported, **kwargs)
    530 def _generate_helper(
    531     self,
    532     prompts: List[str],
   (...)
    536     **kwargs: Any,
    537 ) -> LLMResult:
    538     try:
    539         output = (
--> 540             self._generate(
    541                 prompts,
    542                 stop=stop,
    543                 # TODO: support multiple run managers
    544                 run_manager=run_managers[0] if run_managers else None,
    545                 **kwargs,
    546             )
    547             if new_arg_supported
    548             else self._generate(prompts, stop=stop)
    549         )
    550     except BaseException as e:
    551         for run_manager in run_managers:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/llms/openai.py:455, in BaseOpenAI._generate(self, prompts, stop, run_manager, **kwargs)
    443     choices.append(
    444         {
    445             "text": generation.text,
   (...)
    452         }
    453     )
    454 else:
--> 455     response = completion_with_retry(
    456         self, prompt=_prompts, run_manager=run_manager, **params
    457     )
    458     if not isinstance(response, dict):
    459         # V1 client returns the response in an PyDantic object instead of
    460         # dict. For the transition period, we deep convert it to dict.
    461         response = response.dict()

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/llms/openai.py:123, in completion_with_retry(llm, run_manager, **kwargs)
    119 @retry_decorator
    120 def _completion_with_retry(**kwargs: Any) -> Any:
    121     return llm.client.create(**kwargs)
--> 123 return _completion_with_retry(**kwargs)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tenacity/__init__.py:289, in BaseRetrying.wraps.<locals>.wrapped_f(*args, **kw)
    287 @functools.wraps(f)
    288 def wrapped_f(*args: t.Any, **kw: t.Any) -> t.Any:
--> 289     return self(f, *args, **kw)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tenacity/__init__.py:379, in Retrying.__call__(self, fn, *args, **kwargs)
    377 retry_state = RetryCallState(retry_object=self, fn=fn, args=args, kwargs=kwargs)
    378 while True:
--> 379     do = self.iter(retry_state=retry_state)
    380     if isinstance(do, DoAttempt):
    381         try:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tenacity/__init__.py:314, in BaseRetrying.iter(self, retry_state)
    312 is_explicit_retry = fut.failed and isinstance(fut.exception(), TryAgain)
    313 if not (is_explicit_retry or self.retry(retry_state)):
--> 314     return fut.result()
    316 if self.after is not None:
    317     self.after(retry_state)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py:449, in Future.result(self, timeout)
    447     raise CancelledError()
    448 elif self._state == FINISHED:
--> 449     return self.__get_result()
    451 self._condition.wait(timeout)
    453 if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py:401, in Future.__get_result(self)
    399 if self._exception:
    400     try:
--> 401         raise self._exception
    402     finally:
    403         # Break a reference cycle with the exception in self._exception
    404         self = None

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tenacity/__init__.py:382, in Retrying.__call__(self, fn, *args, **kwargs)
    380 if isinstance(do, DoAttempt):
    381     try:
--> 382         result = fn(*args, **kwargs)
    383     except BaseException:  # noqa: B902
    384         retry_state.set_exception(sys.exc_info())  # type: ignore[arg-type]

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/llms/openai.py:121, in completion_with_retry.<locals>._completion_with_retry(**kwargs)
    119 @retry_decorator
    120 def _completion_with_retry(**kwargs: Any) -> Any:
--> 121     return llm.client.create(**kwargs)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/completion.py:25, in Completion.create(cls, *args, **kwargs)
     23 while True:
     24     try:
---> 25         return super().create(*args, **kwargs)
     26     except TryAgain as e:
     27         if timeout is not None and time.time() > start + timeout:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/abstract/engine_api_resource.py:155, in EngineAPIResource.create(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)
    129 @classmethod
    130 def create(
    131     cls,
   (...)
    138     **params,
    139 ):
    140     (
    141         deployment_id,
    142         engine,
   (...)
    152         api_key, api_base, api_type, api_version, organization, **params
    153     )
--> 155     response, _, api_key = requestor.request(
    156         "post",
    157         url,
    158         params=params,
    159         headers=headers,
    160         stream=stream,
    161         request_id=request_id,
    162         request_timeout=request_timeout,
    163     )
    165     if stream:
    166         # must be an iterator
    167         assert not isinstance(response, OpenAIResponse)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_requestor.py:299, in APIRequestor.request(self, method, url, params, headers, files, stream, request_id, request_timeout)
    278 def request(
    279     self,
    280     method,
   (...)
    287     request_timeout: Optional[Union[float, Tuple[float, float]]] = None,
    288 ) -> Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], bool, str]:
    289     result = self.request_raw(
    290         method.lower(),
    291         url,
   (...)
    297         request_timeout=request_timeout,
    298     )
--> 299     resp, got_stream = self._interpret_response(result, stream)
    300     return resp, got_stream, self.api_key

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_requestor.py:710, in APIRequestor._interpret_response(self, result, stream)
    702     return (
    703         self._interpret_response_line(
    704             line, result.status_code, result.headers, stream=True
    705         )
    706         for line in parse_stream(result.iter_lines())
    707     ), True
    708 else:
    709     return (
--> 710         self._interpret_response_line(
    711             result.content.decode("utf-8"),
    712             result.status_code,
    713             result.headers,
    714             stream=False,
    715         ),
    716         False,
    717     )

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_requestor.py:775, in APIRequestor._interpret_response_line(self, rbody, rcode, rheaders, stream)
    773 stream_error = stream and "error" in resp.data
    774 if stream_error or not 200 <= rcode < 300:
--> 775     raise self.handle_error_response(
    776         rbody, rcode, resp.data, rheaders, stream_error=stream_error
    777     )
    778 return resp

InvalidRequestError: The model `text-davinci-003` has been deprecated, learn more here: ...

1 Like

I found resolution from coding of the online course.

llm_replacement_model = OpenAI(temperature=0, 
                               model='gpt-3.5-turbo-instruct')

response = index.query(query, 
                       llm = llm_replacement_model)

Just adding some extra info that helped narrow the issue down for me.

I’m running Windows and no amount of changing the version of docarray nor pydantic helped.

Finally I realised that loader.load() failed loading the csv and upon further investigation I needed loader = CSVLoader(file_path=file, encoding="utf-8")

only then did !pip install pydantic==1.10.13 have the desired effect.

Working versions:

pydantic==1.10.13
docarray==0.40.0
langchain==0.1.10
1 Like