Find answers from the community

Updated 3 months ago

Nodes

I am using a query engine. I want to query in such a manner that once a query is answered, the nodes used to answer that query should be dropped from the index before answering the next query and so on. Is it possible?
W
k
10 comments
Not sure why you wanna do this but yes this can be achieved.

Plain Text
index.delete_ref_doc("doc_id_0", delete_from_docstore=True)
Use the ID from the nodes to delete these.

I think you'll have to create the query_engine instance.
Thank you @WhiteFang_Jr
Plain Text
 if st.session_state.messages[-1]["role"] != "assistant":
            with st.chat_message("assistant"):
                with st.spinner("Thinking..."):
                            base_retriever = index.as_retriever(similarity_top_k=3)
                            llm = OpenAI(model="gpt-3.5-turbo")
                            service_context = ServiceContext.from_defaults(llm=llm)
                            query_engine_base = RetrieverQueryEngine.from_args(base_retriever, service_context=service_context,qa_prompt=qa_prompt)
                            response = query_engine_base.query(prompt)
                            st.write(response.response)
                            if "sorry" in response.response or "not mentioned in" in response.response or "couldn't find in context" in response.response or "does not provide" in response.response:
                                for i in range(len(response.source_nodes)):
                                      print(str(response.source_nodes[i].id_))
                                      index.delete(response.source_nodes[i].id_) 
Hey the index doesn't get updated. if I use index=index.delete(node_id) it says AttributeError: 'NoneType' object has no attribute 'delete'
It's the same with index.delete_ref_doc("doc_id_0", delete_from_docstore=True)
Hey did you check, if the nodes are still present?
Also make sure you pass the doc_id for deleting
Hey sorry for getting back late. I've resolved the issue. Thansk for all the help
Add a reply
Sign up and join the conversation on Discord