import streamlit as st
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from rag_pipeline import VectorStore
import json
st.title("🔍 Search Test")
vector_store = VectorStore(use_local=True)
query = st.text_input("Enter your query", placeholder="What are the challenges in RAG systems?")
top_k = st.slider("Number of results", 1, 10, 5)
if st.button("Search") and query:
with st.spinner("Searching..."):
import time
start = time.time()
results_raw = vector_store.search(query, top_k)
query_time = (time.time() - start) * 1000
results = {
'query': query,
'total_results': len(results_raw),
'query_time_ms': query_time,
'results': results_raw
}
st.success(f"Found {results['total_results']} results in {results['query_time_ms']:.2f}ms")
for idx, result in enumerate(results['results'], 1):
with st.expander(f"Result {idx} - Score: {result['score']:.3f}"):
st.markdown(f"**Source:** {result['metadata'].get('title', 'Unknown')}")
st.markdown(f"**Page:** {result['metadata'].get('page', 'N/A')}")
st.markdown(f"**Keywords:** {result['metadata'].get('keywords', '')}")
st.text_area("Content", result['text'], height=150, key=f"result_{idx}")
# Export option
if st.button("Export Results as JSON"):
st.download_button(
"Download JSON",
json.dumps(results, indent=2),
file_name=f"search_results_{query[:20]}.json",
mime="application/json"
)