The present application relates to the technical field of
artificial intelligence, in particular to a multi-path RAG context weighted enhanced retrieval driven NL2
SQL generation method and device. The method comprises the following steps: receiving and preprocessing a
natural language query text of
user input to obtain a multi-dimensional query vector; performing multi-path context retrieval in parallel based on the multi-dimensional query vector to obtain a
retrieval result set; assembling the retrieval results of the
retrieval result set into
system prompt words and inputting the
system prompt words into a large
language model to obtain
SQL generation instructions returned by the large
language model; and executing the
SQL generation instructions. Through virtual key markers and virtual key coverage rules, when a filtering condition string contains a virtual key marker, the large
language model is instructed to generate a filtering condition using a
text value in an equal comparison and to switch to an identification column and identification value to generate a filtering condition in a range comparison, so that the large language model can generate a correct SQL statement in a range comparison query without understanding the underlying ID coding, thereby solving the problem of understanding the underlying ID coding of the large language model.