How to hold all the status containers generated during retrieving? #18

Open
opened 2026-02-15 19:15:22 -05:00 by yindo · 0 comments
Owner

Originally created by @cehao628 on GitHub (Sep 15, 2023).

Thanks for your amazing work.

`class PrintRetrievalHandler(BaseCallbackHandler):
def init(self, container):
self.status = container.status("Context Retrieval")

def on_retriever_start(self, serialized: dict, query: str, **kwargs):
    self.status.write(f"**Question:** {query}")
    self.status.update(label=f"**Context Retrieval:** {query}")

def on_retriever_end(self, documents, **kwargs):
    for idx, doc in enumerate(documents):
        source = os.path.basename(doc.metadata["source"])
        self.status.write(f"**Document {idx} from {source}**")
        self.status.markdown(doc.page_content)
    self.status.update(state="complete")`

Here a status container is initialized. But the last one will disappear when starting a new retrieval. I know in streamlit, the session_state is used to store the objects, but I am new in streamlit, and I failed to implement.

Thanks for your attention. I appreciate it a lot.

Originally created by @cehao628 on GitHub (Sep 15, 2023). Thanks for your amazing work. `class PrintRetrievalHandler(BaseCallbackHandler): def __init__(self, container): self.status = container.status("**Context Retrieval**") def on_retriever_start(self, serialized: dict, query: str, **kwargs): self.status.write(f"**Question:** {query}") self.status.update(label=f"**Context Retrieval:** {query}") def on_retriever_end(self, documents, **kwargs): for idx, doc in enumerate(documents): source = os.path.basename(doc.metadata["source"]) self.status.write(f"**Document {idx} from {source}**") self.status.markdown(doc.page_content) self.status.update(state="complete")` Here a status container is initialized. But the last one will disappear when starting a new retrieval. I know in streamlit, the session_state is used to store the objects, but I am new in streamlit, and I failed to implement. Thanks for your attention. I appreciate it a lot.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/streamlit-agent#18