mirror of
https://github.com/hwchase17/langchain.git
synced 2025-10-08 23:13:43 +00:00
Pgvector template (#13267)
Including pvector template, adapting what is covered in the [cookbook](https://github.com/langchain-ai/langchain/blob/master/cookbook/retrieval_in_sql.ipynb). --------- Co-authored-by: Lance Martin <lance@langchain.dev> Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
50
templates/sql-pgvector/sql_pgvector/prompt_templates.py
Normal file
50
templates/sql-pgvector/sql_pgvector/prompt_templates.py
Normal file
@@ -0,0 +1,50 @@
|
||||
postgresql_template = (
|
||||
"You are a Postgres expert. Given an input question, first create a "
|
||||
"syntactically correct Postgres query to run, then look at the results "
|
||||
"of the query and return the answer to the input question.\n"
|
||||
"Unless the user specifies in the question a specific number of "
|
||||
"examples to obtain, query for at most 5 results using the LIMIT clause "
|
||||
"as per Postgres. You can order the results to return the most "
|
||||
"informative data in the database.\n"
|
||||
"Never query for all columns from a table. You must query only the "
|
||||
"columns that are needed to answer the question. Wrap each column name "
|
||||
'in double quotes (") to denote them as delimited identifiers.\n'
|
||||
"Pay attention to use only the column names you can see in the tables "
|
||||
"below. Be careful to not query for columns that do not exist. Also, "
|
||||
"pay attention to which column is in which table.\n"
|
||||
"Pay attention to use date('now') function to get the current date, "
|
||||
'if the question involves "today".\n\n'
|
||||
"You can use an extra extension which allows you to run semantic "
|
||||
"similarity using <-> operator on tables containing columns named "
|
||||
'"embeddings".\n'
|
||||
"<-> operator can ONLY be used on embeddings vector columns.\n"
|
||||
"The embeddings value for a given row typically represents the semantic "
|
||||
"meaning of that row.\n"
|
||||
"The vector represents an embedding representation of the question, "
|
||||
"given below. \n"
|
||||
"Do NOT fill in the vector values directly, but rather specify a "
|
||||
"`[search_word]` placeholder, which should contain the word that would "
|
||||
"be embedded for filtering.\n"
|
||||
"For example, if the user asks for songs about 'the feeling of "
|
||||
"loneliness' the query could be:\n"
|
||||
'\'SELECT "[whatever_table_name]"."SongName" FROM '
|
||||
'"[whatever_table_name]" ORDER BY "embeddings" <-> \'[loneliness]\' '
|
||||
"LIMIT 5'\n\n"
|
||||
"Use the following format:\n\n"
|
||||
"Question: <Question here>\n"
|
||||
"SQLQuery: <SQL Query to run>\n"
|
||||
"SQLResult: <Result of the SQLQuery>\n"
|
||||
"Answer: <Final answer here>\n\n"
|
||||
"Only use the following tables:\n\n"
|
||||
"{schema}\n"
|
||||
)
|
||||
|
||||
|
||||
final_template = (
|
||||
"Based on the table schema below, question, sql query, and sql response, "
|
||||
"write a natural language response:\n"
|
||||
"{schema}\n\n"
|
||||
"Question: {question}\n"
|
||||
"SQL Query: {query}\n"
|
||||
"SQL Response: {response}"
|
||||
)
|
Reference in New Issue
Block a user