karthikvarunn commited on
Commit
f854559
·
verified ·
1 Parent(s): f7ca5e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -16
app.py CHANGED
@@ -17,7 +17,6 @@ import gradio as gr
17
  from pinecone import Pinecone, ServerlessSpec
18
  import openai
19
 
20
- # Load environment variables
21
  load_dotenv()
22
 
23
  # Initialize OpenAI and Pinecone credentials
@@ -51,10 +50,8 @@ embeddings = VoyageAIEmbeddings(
51
 
52
  def search_documents(query):
53
  try:
54
- # Initialize the vector store and retriever
55
  vector_store = PineconeVectorStore(index_name=pinecone_index_name, embedding=embeddings)
56
 
57
- # Use maxMarginalRelevanceSearch to improve diversity in results
58
  results = vector_store.max_marginal_relevance_search(query, k=7, fetch_k=20) # Adjust fetch_k for more diverse results
59
 
60
  # Filter results to ensure uniqueness based on metadata.id
@@ -105,7 +102,6 @@ def generate_output(context, query):
105
  def complete_workflow(query):
106
  try:
107
  context_data, combined_context = search_documents(query)
108
- #natural_language_output = generate_output(combined_context, query)
109
 
110
  document_titles = list({os.path.basename(doc["title"]) for doc in context_data}) # Get only file names
111
 
@@ -131,18 +127,6 @@ def complete_workflow(query):
131
  return {"results": []}, f"Error in workflow: {str(e)}"
132
 
133
 
134
- def delete_index():
135
- try:
136
- pinecone_index_name = "rag-proto011"
137
- if pinecone_index_name in pc.list_indexes().names():
138
- pc.delete_index(name=pinecone_index_name)
139
- return "Pinecone Index Deleted"
140
- else:
141
- return "Pinecone Index Had Already Been Deleted"
142
- except Exception as e:
143
- return f"Error deleting Pinecone index: {str(e)}"
144
-
145
-
146
  def gradio_app():
147
  with gr.Blocks(css=".result-output {width: 150%; font-size: 16px; padding: 10px;}") as app:
148
  gr.Markdown("### Intelligent Document Search Prototype-v0.1.2 ")
 
17
  from pinecone import Pinecone, ServerlessSpec
18
  import openai
19
 
 
20
  load_dotenv()
21
 
22
  # Initialize OpenAI and Pinecone credentials
 
50
 
51
  def search_documents(query):
52
  try:
 
53
  vector_store = PineconeVectorStore(index_name=pinecone_index_name, embedding=embeddings)
54
 
 
55
  results = vector_store.max_marginal_relevance_search(query, k=7, fetch_k=20) # Adjust fetch_k for more diverse results
56
 
57
  # Filter results to ensure uniqueness based on metadata.id
 
102
  def complete_workflow(query):
103
  try:
104
  context_data, combined_context = search_documents(query)
 
105
 
106
  document_titles = list({os.path.basename(doc["title"]) for doc in context_data}) # Get only file names
107
 
 
127
  return {"results": []}, f"Error in workflow: {str(e)}"
128
 
129
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  def gradio_app():
131
  with gr.Blocks(css=".result-output {width: 150%; font-size: 16px; padding: 10px;}") as app:
132
  gr.Markdown("### Intelligent Document Search Prototype-v0.1.2 ")