AttributeError: 'dict' object has no attribute 'replace' #27997
Unanswered
SaiSanthosh1508
asked this question in
Q&A
Replies: 1 comment 2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
`{
"name": "AttributeError",
"message": "'dict' object has no attribute 'replace'",
"stack": "---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[67], line 1
----> 1 rag_chain.invoke({"question":"What is the state of the union?"})
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_core\runnables\base.py:3022, in RunnableSequence.invoke(self, input, config, **kwargs)
3020 context.run(_set_config_context, config)
3021 if i == 0:
-> 3022 input = context.run(step.invoke, input, config, **kwargs)
3023 else:
3024 input = context.run(step.invoke, input, config)
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_core\runnables\base.py:3727, in RunnableParallel.invoke(self, input, config, **kwargs)
3722 with get_executor_for_config(config) as executor:
3723 futures = [
3724 executor.submit(_invoke_step, step, input, config, key)
3725 for key, step in steps.items()
3726 ]
-> 3727 output = {key: future.result() for key, future in zip(steps, futures)}
3728 # finish the root run
3729 except BaseException as e:
File ~\AppData\Local\Programs\Python\Python312\Lib\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 ~\AppData\Local\Programs\Python\Python312\Lib\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 ~\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\thread.py:58, in _WorkItem.run(self)
55 return
57 try:
---> 58 result = self.fn(*self.args, **self.kwargs)
59 except BaseException as exc:
60 self.future.set_exception(exc)
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_core\runnables\base.py:3711, in RunnableParallel.invoke.._invoke_step(step, input, config, key)
3709 context = copy_context()
3710 context.run(_set_config_context, child_config)
-> 3711 return context.run(
3712 step.invoke,
3713 input,
3714 child_config,
3715 )
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_core\retrievers.py:254, in BaseRetriever.invoke(self, input, config, **kwargs)
252 except Exception as e:
253 run_manager.on_retriever_error(e)
--> 254 raise e
255 else:
256 run_manager.on_retriever_end(
257 result,
258 )
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_core\retrievers.py:247, in BaseRetriever.invoke(self, input, config, **kwargs)
245 _kwargs = kwargs if self._expects_other_args else {}
246 if self._new_arg_supported:
--> 247 result = self._get_relevant_documents(
248 input, run_manager=run_manager, **_kwargs
249 )
250 else:
251 result = self._get_relevant_documents(input, **_kwargs)
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_core\vectorstores\base.py:1080, in VectorStoreRetriever._get_relevant_documents(self, query, run_manager)
1076 def _get_relevant_documents(
1077 self, query: str, *, run_manager: CallbackManagerForRetrieverRun
1078 ) -> list[Document]:
1079 if self.search_type == "similarity":
-> 1080 docs = self.vectorstore.similarity_search(query, **self.search_kwargs)
1081 elif self.search_type == "similarity_score_threshold":
1082 docs_and_similarities = (
1083 self.vectorstore.similarity_search_with_relevance_scores(
1084 query, **self.search_kwargs
1085 )
1086 )
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_community\vectorstores\faiss.py:641, in FAISS.similarity_search(self, query, k, filter, fetch_k, **kwargs)
621 def similarity_search(
622 self,
623 query: str,
(...)
627 **kwargs: Any,
628 ) -> List[Document]:
629 """Return docs most similar to query.
630
631 Args:
(...)
639 List of Documents most similar to the query.
640 """
--> 641 docs_and_scores = self.similarity_search_with_score(
642 query, k, filter=filter, fetch_k=fetch_k, **kwargs
643 )
644 return [doc for doc, _ in docs_and_scores]
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_community\vectorstores\faiss.py:513, in FAISS.similarity_search_with_score(self, query, k, filter, fetch_k, **kwargs)
489 def similarity_search_with_score(
490 self,
491 query: str,
(...)
495 **kwargs: Any,
496 ) -> List[Tuple[Document, float]]:
497 """Return docs most similar to query.
498
499 Args:
(...)
511 L2 distance in float. Lower score represents more similarity.
512 """
--> 513 embedding = self._embed_query(query)
514 docs = self.similarity_search_with_score_by_vector(
515 embedding,
516 k,
(...)
519 **kwargs,
520 )
521 return docs
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_community\vectorstores\faiss.py:265, in FAISS._embed_query(self, text)
263 def _embed_query(self, text: str) -> List[float]:
264 if isinstance(self.embedding_function, Embeddings):
--> 265 return self.embedding_function.embed_query(text)
266 else:
267 return self.embedding_function(text)
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_huggingface\embeddings\huggingface.py:108, in HuggingFaceEmbeddings.embed_query(self, text)
99 def embed_query(self, text: str) -> List[float]:
100 """Compute query embeddings using a HuggingFace transformer model.
101
102 Args:
(...)
106 Embeddings for the text.
107 """
--> 108 return self.embed_documents([text])[0]
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_huggingface\embeddings\huggingface.py:79, in HuggingFaceEmbeddings.embed_documents(self, texts)
69 """Compute doc embeddings using a HuggingFace transformer model.
70
71 Args:
(...)
75 List of embeddings, one for each text.
76 """
77 import sentence_transformers # type: ignore[import]
---> 79 texts = list(map(lambda x: x.replace("
", " "), texts))
80 if self.multi_process:
81 pool = self._client.start_multi_process_pool()
File d:\Sunny-Savita\venv\Lib\site-packages\langchain_huggingface\embeddings\huggingface.py:79, in HuggingFaceEmbeddings.embed_documents..(x)
69 """Compute doc embeddings using a HuggingFace transformer model.
70
71 Args:
(...)
75 List of embeddings, one for each text.
76 """
77 import sentence_transformers # type: ignore[import]
---> 79 texts = list(map(lambda x: x.replace("
", " "), texts))
80 if self.multi_process:
81 pool = self._client.start_multi_process_pool()
AttributeError: 'dict' object has no attribute 'replace'"
}`
Im getting this issue,I've seen some youtube videos where the code was correctly executed,is there an issue with my code or with the langchain usage
System Info
Package Information
Beta Was this translation helpful? Give feedback.
All reactions