The invention discloses a context poisoning
attack defense method oriented to an RAG application, and relates to the technical field of RAG. the method comprises the following steps: inputting a target
query statement, and retrieving the target
query statement to obtain multiple pieces of context information; taking representative sentences in the retrieved context information, and identifying and filtering potential malicious template clusters; the big
language model gives all candidate answers according to existing context information, the logarithmic probability of all contexts to different candidate answers is calculated, and after the influence of parameter knowledge of the big
language model is removed from the logarithmic probability, the support degree of all contexts to different candidate answers is obtained; the whole logarithmic
probability vector is used as a support
degree distribution condition of the context to the candidate answers; identifying a single piece of harmful information from the support
degree distribution condition of the context to the candidate answers through a
logistic regression model so as to filter wrong answers; according to the
attack defense method provided by the invention, centralized injection of multiple malicious texts and sparse injection of a small number of malicious texts can be defended.