I would like to build a multipage streamlit app that uses a database (weaviate with langchain). The db object should be shared across all users and all pages so I only use one db instance (this instance loads a retriever model from langchain so uses a bit of RAM).
I tried using @st.cache_resource and outsourcing it into another file. So the same function get’s called by all pages:
def get_database() -> EmbeddingDatabase:
Unfortunately this doesn’t work. Session state is also not usable because it is replicated for each user. Has anyone another idea what the correct approach would be?
- Streamlit version: 1.26.0
- Python version: 3.10.12
- OS version: Linux
(can append if needed, but I think it is not neccesary)
Thanks for any suggestions!!!
As far as I can tell the correct approach isthe one you are using and it does work for me.
Hi, I also cannot get it working in a multi page app.
In the app.py I use:
## initialize connection via snowpark ######################
conn = st.experimental_connection('snowpark', type='snowpark', max_entries=20, ttl=600)
conn = get_snowpark_connection()
But in all other pages in the pages folder,
conn = get_snowpark_connection() is not working,
because get_snowpark_connection() is not existing there.
Maybe I am doing it wrong.
In that case it would be great to get some snippets to do it right.
One straighforward way of having the connection available in all pages is storing it in
st.session_state.conn = get_snowpark_connection()
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.