The provided code snippet contains a
for loop that iterates over the range of numbers [0, 1] (since
range(2) generates [0, 1]). As a result, the loop will only execute twice, once for
row = 0 and once for
row = 1.
In each iteration of the
for loop, the code performs various operations on
supply_insights_docs and eventually creates a new database
new_db. The issue is that
new_db is overwritten in each iteration, so only the last iteration's value of
new_db will be retained, and the previous ones will be lost.
If the intention is to keep the results for all iterations, you need to modify the code to store the results from each iteration in a collection (e.g., a list) instead of overwriting the same variable. For example:
if run_supply_insights: df_supply_insights_questions = pd.read_csv(supply_insights_questions) supply_insights_results =  # Create an empty list to store results for row in range(2): supply_insights_docs = text_splitter.create_documents([df_supply_insights.loc[row]['slack_message']]) for supply_doc in supply_insights_docs: supply_doc.metadata['supplier_name'] = df_supply_insights.loc[row]['supplier_name'] supply_doc.metadata['raw_text'] = df_supply_insights.loc[row]['slack_message'] new_db = create_chromadb_vectorstore(document_list=supply_insights_docs) llm_parser = DiscoveryLLMParser(vectorstore=new_db) df_supply_insights_questions[['structured_output', 'raw_answer']] = df_supply_insights_questions.apply(get_structured_output, axis=1, result_type='expand') df_supply_insights_questions['name'] = df_supply_insights.loc[row]['supplier_name'] df_supply_insights_questions['text'] = df_supply_insights.loc[row]['slack_message'] supply_insights_results.append(df_supply_insights_questions.copy()) # Store the results for this iteration # Now you have all the results from each iteration in supply_insights_results list
With this modification,
supply_insights_results will contain the results for each iteration of the loop, preserving the data from all iterations.