combine these two code segments,
such that if answer is not available in similarity based solution then it will go to llm based solution whose code is in predict function
def preprocess_input(usertext):
    dates = list(datefinder.find_dates(usertext))
    print('dates',dates)
    if dates:
        # Use the first detected date
        formatted_date = dates[0].strftime("%d-%b-%Y")
        filtered_df = new_df[new_df['date'] == formatted_date]  # Filter for matching date
    else:
        # Filter for entries without a valid date
        filtered_df = new_df[new_df['date'] == 'NO_DATE']
    print(filtered_df)
    if filtered_df.empty:
        return None, "No matching data found for your query."
    return filtered_df, None

def get_most_similar_question(userText,history):
    filtered_df, error_msg = preprocess_input(userText.lower())
    if filtered_df is None:
        return error_msg
    
    filtered_df['Question'] = filtered_df['Question'].str.lower()
    question_list = filtered_df["Question"].to_list()
    question_embeddings = retrieval_model.encode(question_list)
    user_text_embedding = retrieval_model.encode([userText.lower()])
#     
    # Calculate similarity scores
    similarity_scores = np.inner(user_text_embedding, question_embeddings).flatten()
    top_match_idx = np.argmax(similarity_scores)
    
    if similarity_scores[top_match_idx] == 0:
        return "Sorry, no similar questions were found for your query."
    
    matched_data = filtered_df.iloc[top_match_idx,[10]]
    return matched_data.to_frame().T.to_html(index=False)  # Returning the matched row as HTML




this is my old code 

def get_most_similar_question(userText, history):
    print(userText)
#     userText = preprocess_user_input(userText)

# You may now use processed_user_query to perform a retrieval using your model
    
    # Compute embedding for the user input text using the initial retrieval model
    inp_emb = retrieval_model.encode([userText])
    # Calculate similarity scores between user input text and data embeddings
    corr = np.inner(inp_emb, data_emb).flatten()
    # Get indices of the top 5 most similar texts
    top_5_idx = np.argsort(corr)[-1:]
#     print('idx',top_5_idx)
    
    top_5_values = corr[top_5_idx]
#     print('values',top_5_values)
    # Retrieve the texts/questions corresponding to these indices
    top_5_texts = new_df.iloc[top_5_idx, 1].values  # Column 1 contains the texts/questions
#     print(top_5_texts)
    
#     data_emb_1 = retrieval_model.encode([top_5_texts])
#     corr_1 = np.inner(inp_emb, data_emb_1).flatten()
#     top_1_idx = np.argsort(corr_1)[-5:]
# #     print('idx',top_1_idx)
    
#     top_1_values = corr_1[top_1_idx]
# #     print('values',top_1_values)
#     top_1_texts = new_df.iloc[top_1_idx, 1].values  # Column 1 contains the texts/questions
#     print(top_1_texts)
#     # Re-encode these top 5 texts using the new retrieval model
#     data_emb_1 = new_retrieval_model(top_5_texts)
#     # Calculate similarity with the input text using the new model's embeddings
#     inp_emb_1 = new_retrieval_model([userText])
#     corr_1 = np.inner(inp_emb_1, data_emb_1).flatten()
#     print('corr_1',corr_1)
    
#     # Identify the highest similarity score and its index
#     top_1_idx = np.argmax(corr_1)
#     print('top_1_idx',top_1_idx)
#     top_1_idx = top_1_idx+1
#     print('top_1_idx_11',top_1_idx)
#     top_1_value = corr_1[top_1_idx]
#     print('top_1_value',top_1_value)
    
#     top_1_texts = top_5_texts[top_1_idx+1]
#     print('top_1_texts',top_1_texts)

    print('Matching score:', top_5_values[0])
#     print('Matching score second time:', top_1_value)
    
    # Decision to call predict or return the highest ranked text based on similarity threshold
    
    if top_5_values[0] < 0.8:
        # Placeholder for the 'predict' function, assuming you have it defined elsewhere to handle insufficient similarity scenarios
        return predict(userText, history)
    else:
        # Crafting a DataFrame to convert to HTML, using top_1_idx to find original index in new_df
        most_similar_data = new_df.iloc[top_5_idx, [1]]  # Adjusted for Python's indexing
        most_similar_data_df = pd.DataFrame(most_similar_data)
        df_html_with_sql = most_similar_data_df.to_html(index=False)
        html_output = f"<h3>Here is the top matching result(s) for your query:</h3>{df_html_with_sql}"
        return html_output