from pinecone import Pinecone, ServerlessSpec
api_key_pinecone = os.getenv("PINECONE_API_KEY")
pc = Pinecone(api_key=api_key_pinecone)
@st.dialog("Create Namespace", width="large")
def create_namespace():
try:
with st.form(key="create_namespace_key"):
namespace_name = st.text_input("Namespace Name")
form_submitted = st.form_submit_button(label="Submit")
if form_submitted:
# Check if the index exists
existing_indexes = list_existing_indexes()
if not any(index.name == st.session_state.index_name for index in existing_indexes):
print("Creating new index")
# Create a new index if it doesn't already exist
pc.create_index(
name=st.session_state.index_name,
dimension=3072,
metric="cosine",
spec=ServerlessSpec(cloud="aws", region="us-east-1"),
)
# Create a new namespace
index = pc.Index(st.session_state.index_name)
# Upsert a dummy vector to create the namespace
index.upsert(
vectors=[
{"id": "dummy", "values": [0.1] * 3072}
],
namespace=namespace_name,
)
index = pc.describe_index(st.session_state.index_name)
described_index = pc.Index(host=index.host)
index_stats = described_index.describe_index_stats()
print("index_stats :",index_stats) // namespaces dictionary is empty, why ?
st.rerun()
except Exception as e:
st.error(f"An error occurred: {str(e)}")
st.sidebar.button("Create Namespace",key=uuid.uuid4(),on_click=create_namespace)
hello everyone, I’m working on a PDF RAG app .
User’s vector data is stored in his own index ( 1 index per user )
I want a feature that my app user be able to create a document collection . this can be done using pinecone namespace .
I’m trying to create one , but I’m running into an issue.
You can see that I did call index.upsert with namespace field , but after that in the next lines when I do describe_index_stats() , I don’t get the newly created namespace name , why ?
When I do a hard refresh ( F5 on keyboard or by clicking the refresh button of browser ) then I’m able to see the newly created namespace