SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.07867 · 2024

PoisonedRAG: Knowledge Corruption Attacks to Retrieval-Augmented Generation of Large Language Models

arXiv · PDF · Open in the Atlas

Code that ran

12 of 17 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 6 honoured the contract we drafted, 2 violated it and 1 has no contract verdict; 3 failures of our instrument; 5 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2402.07867.json · badge: /api/ran/2402.07867.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
sleeepeer/poisonedrag canonical (classifier label)
classifier basis: census
10 ran · 5 no recorded run
agrzheng/GRADA community (classifier label)
classifier basis: plan_row
2 ran · 0 no recorded run
FunctionStatusWhere it lives
ance_get_emb Ran
ran, honoured the contract we drafted
sleeepeer/poisonedrag/src/utils.py
code served (permissive licence) · get_code("27c0647865d4872e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockANCEModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.embedding = nn.Linear(4, 8)
    
    def forward(self, input_dict):
        # Expects input_dict with 'input_ids' and possibly 'attention_mask'
        # Returns a dict with 'sentence_embedding' key
        input_ids = input_dict['input_ids']
        embeddings = self.embedding(input_ids.float())
        sentence_embedding = embeddings.mean(dim=1)
        return {'sentence_embedding': sentence_embedding}

model = MockANCEModel()

input_dict = {
    'input_ids': torch.randint(0, 100, (2, 4)),
    'attention_mask': torch.ones(2, 4),
    'token_type_ids': torch.zeros(2, 4)
}

ARGS = {
    'model': model,
    'input': input_dict
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
check_answer Ran
ran, violated the contract we drafted
sleeepeer/poisonedrag/src/contriever_src/evaluation.py
pointer only (licence: MIT); the stored copy get_code serves, from facebookresearch/contriever, is pointer only (licence: NOASSERTION) · get_code("637b51b8df78832a")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from facebookresearch/contriever, and GitHub could not classify the licence of that repository (NOASSERTION). The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

contriever_get_emb Ran
ran, honoured the contract we drafted
sleeepeer/poisonedrag/src/utils.py
code served (permissive licence) · get_code("a1619cb3b16730df")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockContrieverModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, **input):
        # The function calls model(**input), so we need to accept keyword arguments
        # A typical contriever model might accept input_ids, attention_mask, etc.
        if 'input_ids' in input:
            x = input['input_ids']
            return self.linear(x.float())
        return torch.randn(2, 4)

model = MockContrieverModel()

input_dict = {
    'input_ids': torch.randint(0, 100, (2, 4)),
    'attention_mask': torch.ones(2, 4)
}

ARGS = {
    'model': model,
    'input': input_dict
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
dpr_get_emb Ran
ran, honoured the contract we drafted
sleeepeer/poisonedrag/src/utils.py
code served (permissive licence) · get_code("a99ade31d3be8eec")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockDPRModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, input_ids=None, attention_mask=None, token_type_ids=None, **kwargs):
        # Minimal forward pass that returns an object with pooler_output
        batch_size = input_ids.shape[0] if input_ids is not None else 2
        pooler_output = torch.randn(batch_size, 3)
        
        class Output:
            pass
        
        output = Output()
        output.pooler_output = pooler_output
        return output

model = MockDPRModel()

input_dict = {
    "input_ids": torch.randint(0, 100, (2, 4)),
    "attention_mask": torch.ones(2, 4, dtype=torch.long),
    "token_type_ids": torch.zeros(2, 4, dtype=torch.long)
}

ARGS = {
    "model": model,
    "input": input_dict
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 3) — shape (2, 3) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
gather Ran
ran, honoured the contract we drafted
sleeepeer/poisonedrag/src/contriever_src/dist_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from facebookresearch/contriever, is pointer only (licence: NOASSERTION) · get_code("9fb6e57668661c38")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from facebookresearch/contriever, and GitHub could not classify the licence of that repository (NOASSERTION). The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

gather_nograd Ran
ran, honoured the contract we drafted
sleeepeer/poisonedrag/src/contriever_src/dist_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from agwaBom/TPOUR, is pointer only (licence: NONE) · get_code("01971cc37e6fe583")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from agwaBom/TPOUR, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

has_answer Ran
ran, violated the contract we drafted
sleeepeer/poisonedrag/src/contriever_src/evaluation.py
pointer only (licence: MIT); the stored copy get_code serves, from facebookresearch/contriever, is pointer only (licence: NOASSERTION) · get_code("fa4ecbff4b9a354b")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from facebookresearch/contriever, and GitHub could not classify the licence of that repository (NOASSERTION). The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

hotflip_attack Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
agrzheng/GRADA/src/attack.py
code served (permissive licence) · get_code("309e71f4157403d6")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 1, dtype family int, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# averaged_grad: a 1D tensor representing gradients
averaged_grad = torch.randn(4)

# embedding_matrix: a 2D tensor where we compute dot products with averaged_grad
# Shape should be (vocab_size, embedding_dim)
embedding_matrix = torch.randn(5, 4)

# increase_loss: boolean flag
increase_loss = False

# num_candidates: number of top candidates to return
num_candidates = 2

# filter: optional tensor to subtract from gradient_dot_embedding_matrix
# Should have same shape as the result of matmul (vocab_size,)
filter = torch.randn(5)

ARGS = {
    "averaged_grad": averaged_grad,
    "embedding_matrix": embedding_matrix,
    "increase_loss": increase_loss,
    "num_candidates": num_candidates,
    "filter": filter,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family int, shape (2,) — shape (2,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
randomcrop Ran
ran; our contract draft was wrong, not the code
sleeepeer/poisonedrag/src/contriever_src/data.py
pointer only (licence: MIT); the stored copy get_code serves, from facebookresearch/contriever, is pointer only (licence: NOASSERTION) · get_code("e037474365501512")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from facebookresearch/contriever, and GitHub could not classify the licence of that repository (NOASSERTION). The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

varsize_gather_nograd Ran
ran, honoured the contract we drafted
sleeepeer/poisonedrag/src/contriever_src/dist_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from facebookresearch/contriever, is pointer only (licence: NOASSERTION) · get_code("b1ad8cd3a7168b7f")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from facebookresearch/contriever, and GitHub could not classify the licence of that repository (NOASSERTION). The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

wrap_prompt Ran
ran; our contract draft was wrong, not the code
sleeepeer/poisonedrag/src/prompts.py
code served (permissive licence) · get_code("183fa5ce0ec5b32b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

ARGS = {
    'question': 'What is the capital of France?',
    'context': 'France is a country in Europe. The capital of France is Paris.',
    'prompt_id': 1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
wrap_prompt Ran
ran on a synthesized input
agrzheng/GRADA/src/prompts.py
code served (permissive licence) · get_code("96494dccb73d03f3")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

ARGS = {
    'question': 'Is this a test?',
    'context': [
        'This is a test document.',
        'It contains multiple lines of context.',
        'Each line provides relevant information.'
    ],
    'prompt_id': 1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
calculate_matches Not yet run
unverified (harvested, no recorded run)
sleeepeer/poisonedrag/src/contriever_src/evaluation.py
pointer only (licence: MIT); the stored copy get_code serves, from facebookresearch/contriever, is pointer only (licence: NOASSERTION) · get_code("7a4988952dd3a127")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from facebookresearch/contriever, and GitHub could not classify the licence of that repository (NOASSERTION). The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

load_data Not yet run
unverified (harvested, no recorded run)
sleeepeer/poisonedrag/src/contriever_src/data.py
code served (permissive licence) · get_code("183aa13a4fe6a0cc")
How it ran

no invocation recorded.

load_dataset Not yet run
unverified (harvested, no recorded run)
sleeepeer/poisonedrag/src/contriever_src/data.py
code served (permissive licence) · get_code("0c21433d8fb86d42")
How it ran

no invocation recorded.

load_retriever Not yet run
unverified (harvested, no recorded run)
sleeepeer/poisonedrag/src/contriever_src/contriever.py
code served (permissive licence) · get_code("02909384e87fd820")
How it ran

no invocation recorded.

query_gpt Not yet run
unverified (harvested, no recorded run)
sleeepeer/poisonedrag/gen_adv.py
code served (permissive licence) · get_code("e238bddbf3216308")
How it ran

no invocation recorded.

Also present in other papers' code

Of 17 samples lifted from this paper's linked repositories, 17 carry a function identity and 0 do not. Of the 17 distinct functions with an identity, 11 are also present in other papers whose code we hold (8 with at least one paper dated earlier, 7 the same month, 8 later) and 6 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
calculate_matches 13 other papers
3 dated earlier, 3 the same month, 7 later
2112.08688 (2021-12)
Evidentiality-guided Generation for Knowledge-Intensive NLP Tasks
2401.03568 (2024-01)
Agent AI: Surveying the Horizons of Multimodal Interaction
2401.16979 (2024-01)
Re3val: Reinforced and Reranked Generative Retrieval
and 10 more not named here
check_answer 13 other papers
3 dated earlier, 3 the same month, 7 later
2112.08688 (2021-12)
Evidentiality-guided Generation for Knowledge-Intensive NLP Tasks
2401.03568 (2024-01)
Agent AI: Surveying the Horizons of Multimodal Interaction
2401.16979 (2024-01)
Re3val: Reinforced and Reranked Generative Retrieval
and 10 more not named here
has_answer 11 other papers
3 dated earlier, 2 the same month, 6 later
2112.08688 (2021-12)
Evidentiality-guided Generation for Knowledge-Intensive NLP Tasks
2401.03568 (2024-01)
Agent AI: Surveying the Horizons of Multimodal Interaction
2401.16979 (2024-01)
Re3val: Reinforced and Reranked Generative Retrieval
and 8 more not named here
varsize_gather_nograd 10 other papers
1 the same month, 9 later
2402.03216 (2024-02)
M3-Embedding: Multi-Linguality, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation
2403.06840 (2024-03)
RA-ISF: Learning to Answer and Understand from Retrieval Augmentation via Iterative Self-Feedback
2404.19705 (2024-04)
When to Retrieve: Teaching LLMs to Utilize Information Retrieval Effectively
and 7 more not named here
gather_nograd 9 other papers
1 the same month, 8 later
2402.03216 (2024-02)
M3-Embedding: Multi-Linguality, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation
2403.06840 (2024-03)
RA-ISF: Learning to Answer and Understand from Retrieval Augmentation via Iterative Self-Feedback
2404.19705 (2024-04)
When to Retrieve: Teaching LLMs to Utilize Information Retrieval Effectively
and 6 more not named here
gather 8 other papers
1 the same month, 7 later
2402.03216 (2024-02)
M3-Embedding: Multi-Linguality, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation
2403.06840 (2024-03)
RA-ISF: Learning to Answer and Understand from Retrieval Augmentation via Iterative Self-Feedback
2404.19705 (2024-04)
When to Retrieve: Teaching LLMs to Utilize Information Retrieval Effectively
and 5 more not named here
randomcrop 7 other papers
1 dated earlier, 1 the same month, 5 later
2310.11511 (2023-10)
Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection
2402.03216 (2024-02)
M3-Embedding: Multi-Linguality, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation
2403.06840 (2024-03)
RA-ISF: Learning to Answer and Understand from Retrieval Augmentation via Iterative Self-Feedback
and 4 more not named here
hotflip_attack 4 other papers
4 dated earlier · 1 only as an assembly brick
2010.15980 (2020-10)
AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Prompts
2106.01751 (2021-06)
Reordering Examples Helps during Priming-based Few-Shot Learning
2305.17826 (2023-05)
NOTABLE: Transferable Backdoor Attacks Against Prompt-based NLP Models
and 1 more not named here
contriever_get_emb 2 other papers
1 dated earlier, 1 later
2310.19156 (2023-10)
Poisoning Retrieval Corpora by Injecting Adversarial Passages
2407.12784 (2024-07)
AgentPoison: Red-teaming LLM Agents via Poisoning Memory or Knowledge Bases
ance_get_emb 1 other paper
1 dated earlier
2310.19156 (2023-10)
Poisoning Retrieval Corpora by Injecting Adversarial Passages
dpr_get_emb 1 other paper
1 dated earlier
2310.19156 (2023-10)
Poisoning Retrieval Corpora by Injecting Adversarial Passages

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Large language models (LLMs) have achieved remarkable success due to their exceptional generative capabilities. Despite their success, they also have inherent limitations such as a lack of up-to-date knowledge and hallucination. Retrieval-Augmented Generation (RAG) is a state-of-the-art technique to mitigate these limitations. The key idea of RAG is to ground the answer generation of an LLM on external knowledge retrieved from a knowledge database. Existing studies mainly focus on improving the accuracy or efficiency of RAG, leaving its security largely unexplored. We aim to bridge the gap in this work. We find that the knowledge database in a RAG system introduces a new and practical attack surface. Based on this attack surface, we propose PoisonedRAG, the first knowledge corruption attack to RAG, where an attacker could inject a few malicious texts into the knowledge database of a RAG system to induce an LLM to generate an attacker-chosen target answer for an attacker-chosen target question. We formulate knowledge corruption attacks as an optimization problem, whose solution is a set of malicious texts. Depending on the background knowledge (e.g., black-box and white-box settings) of an attacker on a RAG system, we propose two solutions to solve the optimization problem, respectively. Our results show PoisonedRAG could achieve a 90% attack success rate when injecting five malicious texts for each target question into a knowledge database with millions of texts. We also evaluate several defenses and our results show they are insufficient to defend against PoisonedRAG, highlighting the need for new defenses.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2402.07867")
get_code_for_paper("2402.07867")
have("2402.07867")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2402.07867.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2402.07867.svg)](https://syntology.ai/paper/2402.07867)

Connect an agent — have() is free.