Update app.py
Browse files
app.py
CHANGED
@@ -74,17 +74,17 @@ if uploaded_file is not None:
|
|
74 |
pdf_vectors = embedding.encode(texts)
|
75 |
vector_count = len(documents)
|
76 |
example_data_generator = map(lambda i: (f'id-{i}', pdf_vectors[i], {"text": texts[i]}), range(vector_count))
|
77 |
-
if '
|
78 |
-
index.delete(delete_all=True,namespace='
|
79 |
for ids_vectors_chunk in chunks(example_data_generator, batch_size=100):
|
80 |
-
index.upsert(vectors=ids_vectors_chunk,namespace='
|
81 |
|
82 |
# Search query related context
|
83 |
sample_query = st.text_input("Stellen Sie eine Frage zu dem PDF: (Ask a question related to the PDF:)")
|
84 |
if st.button("Abschicken (Submit)"):
|
85 |
if uploaded_file is not None and sample_query:
|
86 |
query_vector = embedding.encode(sample_query).tolist()
|
87 |
-
query_search = index.query(vector=query_vector, top_k=5, include_metadata=True
|
88 |
|
89 |
matched_contents = [match["metadata"]["text"] for match in query_search["matches"]]
|
90 |
|
|
|
74 |
pdf_vectors = embedding.encode(texts)
|
75 |
vector_count = len(documents)
|
76 |
example_data_generator = map(lambda i: (f'id-{i}', pdf_vectors[i], {"text": texts[i]}), range(vector_count))
|
77 |
+
if '( Default )' in index.describe_index_stats()['namespaces']:
|
78 |
+
index.delete(delete_all=True,namespace='( Default )')
|
79 |
for ids_vectors_chunk in chunks(example_data_generator, batch_size=100):
|
80 |
+
index.upsert(vectors=ids_vectors_chunk,namespace='( Default )')
|
81 |
|
82 |
# Search query related context
|
83 |
sample_query = st.text_input("Stellen Sie eine Frage zu dem PDF: (Ask a question related to the PDF:)")
|
84 |
if st.button("Abschicken (Submit)"):
|
85 |
if uploaded_file is not None and sample_query:
|
86 |
query_vector = embedding.encode(sample_query).tolist()
|
87 |
+
query_search = index.query(vector=query_vector, top_k=5, include_metadata=True)
|
88 |
|
89 |
matched_contents = [match["metadata"]["text"] for match in query_search["matches"]]
|
90 |
|