User Query Recommnedation #14427
Replies: 1 comment 2 replies
-
Hello @Esg-developers! I'm here to help you with any bugs, questions, or contributions you may have. If you need assistance, feel free to ask. To build a query recommendation pipeline using the
Here is a simplified example in Python: import pandas as pd
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
# Step 1: Load metadata
metadata = pd.read_csv('metadata.csv')
# Step 2: Create embeddings
model = SentenceTransformer('all-MiniLM-L6-v2')
column_embeddings = model.encode(metadata['column_definition'].tolist())
# Step 3: Build a vector store (using a simple in-memory approach)
vector_store = {metadata['column_name'][i]: column_embeddings[i] for i in range(len(metadata))}
# Step 4: Query pipeline
def recommend_columns(query, top_k=5):
query_embedding = model.encode([query])[0]
similarities = {col: cosine_similarity([query_embedding], [emb])[0][0] for col, emb in vector_store.items()}
recommended_columns = sorted(similarities, key=similarities.get, reverse=True)[:top_k]
return recommended_columns
# Example usage
query = "Find the user email"
recommended_columns = recommend_columns(query)
print("Recommended columns:", recommended_columns) For more advanced implementations, refer to the Text-to-SQL from Scratch guide. This guide includes advanced capabilities such as query-time table retrieval and query-time row retrieval, which can significantly enhance the performance and accuracy of your text-to-SQL pipeline [1][2]. |
Beta Was this translation helpful? Give feedback.
-
Hi Team
I have a RAG application, which is responsible for performing text-to-sql. After a user query comes in and complete the execution, along with the output of that query i want to give 3-5 more recommended queries to prompt in the chatbot.
consider i have the metadata.csv consisting of column names and its definitions.
So using this data how can i build the query recommendation pipeline?
Thanks, Pradipta
Beta Was this translation helpful? Give feedback.
All reactions