TypeError: ‘HuggingFaceEmbeddings’ object is not callable
I have written bellow code and getting error given above.
As per best of my understanding what i have done is:
- The
download_hugging_face_embedding()
function creates an instance of theHuggingFaceEmbeddings
class with the specified model name ("sentence-transformers/all-MiniLM-L6-v2"
). - The
embedding
variable is assigned the result of callingdownload_hugging_face_embedding()
, which is theHuggingFaceEmbeddings
instance. - The
PineconeStore
is created using theembedding
instance, and thetext_key
parameter is set to"text"
. - The
RetrievalQA
chain is created using thePineconeStore
'sas_retriever()
method, with thesearch_kwargs
parameter set to{'k': 2}
. - passing the input to the
qa
object, and prints the result.
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
PROMPT=PromptTemplate(template=prompt_template, input_variables=["context", "question"])
chain_type_kwargs={"prompt": PROMPT}
llm = None
path_to_model = r'C:\Users\Naruto\Desktop\generative_ai\generative_ai_material\project\Medical_Chat_Bot\model\llama-2-7b-chat.ggmlv3.q4_0.bin'
llm = CTransformers(
model=path_to_model,
model_type='llama',
config={'max_new_tokens':552,
'temperature':0.8}
)
vectordb = PineconeStore(index, embedding, text_key="text")
qa=RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=vectordb.as_retriever(search_kwargs={'k': 2}),
return_source_documents=True,
chain_type_kwargs=chain_type_kwargs)
result=qa({"query": question})
FULL ERROR:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[66], line 1
----> 1 result=qa({"query": question})
File c:\Users\Naruto\Desktop\generative_ai\generative_ai_material\project\Medical_Chat_Bot\mcbvenv\lib\site-packages\langchain\chains\base.py:181, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
179 except (KeyboardInterrupt, Exception) as e:
180 run_manager.on_chain_error(e)
--> 181 raise e
182 run_manager.on_chain_end(outputs)
183 final_outputs: Dict[str, Any] = self.prep_outputs(
184 inputs, outputs, return_only_outputs
185 )
File c:\Users\Naruto\Desktop\generative_ai\generative_ai_material\project\Medical_Chat_Bot\mcbvenv\lib\site-packages\langchain\chains\base.py:175, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
169 run_manager = callback_manager.on_chain_start(
170 dumpd(self),
171 inputs,
172 )
173 try:
174 outputs = (
--> 175 self._call(inputs, run_manager=run_manager)
176 if new_arg_supported
177 else self._call(inputs)
178 )
...
(...)
125 filter=filter,
126 )
TypeError: 'HuggingFaceEmbeddings' object is not callable
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
if I am doing result=qa.run({"query": question})
also not working. ERROR as bellow
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[71], line 1
----> 1 result=qa.run({"query": question})
File c:\Users\Naruto\Desktop\generative_ai\generative_ai_material\project\Medical_Chat_Bot\mcbvenv\lib\site-packages\langchain\chains\base.py:310, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
308 """Run the chain as text in, text out or multiple variables, text out."""
309 # Run at start to make sure this is possible/defined
--> 310 _output_key = self._run_output_key
312 if args and not kwargs:
313 if len(args) != 1:
File c:\Users\Naruto\Desktop\generative_ai\generative_ai_material\project\Medical_Chat_Bot\mcbvenv\lib\site-packages\langchain\chains\base.py:294, in Chain._run_output_key(self)
291 @property
292 def _run_output_key(self) -> str:
293 if len(self.output_keys) != 1:
--> 294 raise ValueError(
295 f"`run` not supported when there is not exactly "
296 f"one output key. Got {self.output_keys}."
297 )
298 return self.output_keys[0]
ValueError: `run` not supported when there is not exactly one output key. Got ['result', 'source_documents'].