KAPipe
KAPipe is a modular framework for building knowledge acquisition systems from unstructured data.
In KAPipe, knowledge acquisition is organized into four stages:
- Extraction: extracting knowledge units from unstructured data.
- Organization: organizing extracted knowledge units into structured representations such as knowledge graph.
- Retrieval: retrieving relevant knowledge for a given request.
- Utilization: using retrieved knowledge to solve for downstream tasks such as question answering.
For each stage, KAPipe provides reusable components that implement specific approaches. For example, KAPipe provides Document-level Relation Extraction and Proposition Extraction components for extraction, and Passage Retrieval and Graph Retrieval components for retrieval. Together, these components serve as building blocks for constructing knowledge acquisition systems.
Note: KAPipe is designed for research and experimentation rather than production use. It is under active development and may introduce breaking changes without prior notice.
KAPipe is used in the following papers:
- Nishida et al., EMNLP 2026, Beyond Retrieval: Structuring Evolving and Inconsistent External Knowledge with Proposition Relations for RAG. (to appear)
Installation
python -m pip install -U kapipe
For local development:
git clone https://github.com/norikinishida/kapipe.git
cd kapipe
python -m pip install -e .
Some pretrained models and configuration files are distributed separately.
mkdir -p ~/.kapipe
mv release.YYYYMMDD.tar.gz ~/.kapipe
cd ~/.kapipe
tar -zxvf release.YYYYMMDD.tar.gz
Release files are available here: Please use the latest release file!
Components
In KAPipe, a component is a modular processing unit that implements a specific approach within one of the four stages: extraction, organization, retrieval, or utilization.
The following table summarizes the components currently supported by KAPipe.
| Stage | Component | Module | Docs | Example |
|---|---|---|---|---|
| Extraction | Named Entity Recognition | kapipe.ner |
Docs | Example |
| Extraction | Entity Disambiguation (Retrieval) | kapipe.ed_retrieval |
Docs | Example |
| Extraction | Entity Disambiguation (Reranking) | kapipe.ed_reranking |
Docs | Example |
| Extraction | Document-level Relation Extraction | kapipe.docre |
Docs | Example |
| Extraction | Proposition Extraction | kapipe.proposition_extraction |
Docs | Example |
| Extraction | Proposition Relation Extraction | kapipe.proposition_relation_extraction |
Docs | Example |
| Extraction | Proposition Relation Refinement | kapipe.proposition_relation_refinement |
Docs | Example |
| Organization | Entity Graph Construction | kapipe.entity_graph_construction |
Docs | Example |
| Organization | Passage Graph Construction | kapipe.passage_graph_construction |
Docs | Example |
| Organization | Community Clustering | kapipe.community_clustering |
Docs | Example |
| Organization | Report Generation | kapipe.report_generation |
Docs | Example |
| Organization | Chunking | kapipe.chunking |
Docs | Example |
| Retrieval | Passage Retrieval | kapipe.passage_retrieval |
Docs | Example |
| Retrieval | Graph Retrieval | kapipe.graph_retrieval |
Docs | Example |
| Utilization | Context Formatting | kapipe.context_formatting |
Docs | Example |
| Utilization | Question Answering | kapipe.qa |
Docs | Example |
Pipelines
Pipelines (kapipe.pipelines) are convenience classes for chaining components that are commonly used together.
They represent selected compositions and are not intended to cover every possible combination of components.
| Pipeline | Description | Docs | Example |
|---|---|---|---|
TripleExtractionPipeline |
Chains NER, Entity Disambiguation (Retrieval), Entity Disambiguation (Reranking), and Document-level Relation Extraction components | Docs | Example |
RAGPipeline |
Chains Passage Retrieval and Question Answering components | Docs | Example |
GraphRAGPipeline |
Chains triple extraction, Entity Graph Construction, Community Clustering, Report Generation, Passage Retrieval, and Question Answering components | Docs | Example |
ProStructRAGPipeline |
Chains Proposition Extraction, Proposition Relation Extraction, Proposition Relation Refinement, Passage Graph Construction, Passage Retrieval, Graph Retrieval, Context Formatting, and Question Answering components | Docs | Example |
Agents
Agents (kapipe.agents) use an LLM to dynamically reason, select Tools, observe Tool-call results, and generate a final response.
Unlike pipelines, which connect components in a predefined sequence, agents decide which action to take based on the request and the execution trajectory.
A Tool can wrap a KAPipe component or any other callable function.
| Agent | Description | Docs | Example |
|---|---|---|---|
ToolCallingAgent |
Performs ReAct-style inference by repeatedly calling Tools and observing their results until it generates a final answer | Docs | Example |
Quickstart
Example 1
This example shows how to instantiate Passage Retrieval and QA components and run Retrieval-Augmented Generation (RAG).
import os
from kapipe import utils
from kapipe.llms import OpenAILLM
from kapipe.passage_retrieval import Qwen3Embedding
from kapipe.qa import LLMQA
# Set input and output paths
data_dir = "experiments/passage_retrieval/data/examples"
index_dir = "./indexes"
# Load passages and questions
passages = utils.read_jsonl(os.path.join(data_dir, "corpus", "passages.jsonl"))
questions = utils.read_json(os.path.join(data_dir, "qa", "questions.json"))
# Instantiate the Passage Retrieval component
passage_retrieval = Qwen3Embedding(
model_name="Qwen/Qwen3-Embedding-0.6B",
max_passage_length=8192,
normalize=True,
metric="inner-product",
query_instruction="Given a question, retrieve relevant passages that answer the question.",
)
# Instantiate the QA component
llm = OpenAILLM(model_name="gpt-5.4-nano", max_new_tokens=8192)
qa = LLMQA(
model=llm,
prompt_template_name_or_path="qa_04_with_context",
)
# Build a retrieval index over passages
passage_retrieval.make_index(
passages=passages,
index_dir=index_dir,
batch_size=64,
)
# Answer questions by chaining retrieval and QA
answers = []
for question in questions:
# Retrieve relevant passages
retrieved_passages = passage_retrieval.search(
queries=[question["question"]],
top_k=5,
)[0]
# Wrap retrieved passages in the QA input format
contexts_for_question = {
"question_key": question["question_key"],
"contexts": retrieved_passages,
}
# Generate an answer
answer = qa.answer(
question=question,
contexts_for_question=contexts_for_question,
)
# Preserve retrieved contexts
answer["contexts"] = retrieved_passages
answers.append(answer)
# Save the results
utils.write_json("./predictions.json", answers)
Example 2
This example shows how to instantiate GraphRAGPipeline, structure knowledge, and run inference with GraphRAG.
The full executable version is available in experiments/graphrag_pipeline_tacl2026.
import os
from kapipe import utils
from kapipe.pipelines import GraphRAGPipeline
from kapipe.llms import OpenAILLM
from kapipe.ner import LLMNER
from kapipe.ed_retrieval import BlinkBiEncoder
from kapipe.ed_reranking import LLMED
from kapipe.docre import LLMDocRE
from kapipe.entity_graph_construction import EntityGraphConstructor
from kapipe.community_clustering import NeighborhoodAggregation
from kapipe.report_generation import TemplateBasedReportGenerator
from kapipe.chunking import Chunker
from kapipe.passage_retrieval import Qwen3Embedding
from kapipe.qa import LLMQA
# Set input and output paths
data_dir = "experiments/graphrag_pipeline_tacl2026/data/examples"
index_dir = "./indexes"
# Load input documents, entity dictionary, and questions
documents = utils.read_json(
os.path.join(data_dir, "docre", "documents.json")
)
entity_dict = utils.read_json(
os.path.join(data_dir, "kb", "entity_dict.json")
)
questions = utils.read_json(
os.path.join(data_dir, "qa", "questions.json")
)
# Instantiate the components
llm = OpenAILLM(model_name="gpt-5.4-nano", max_new_tokens=8192)
ner = LLMNER.from_identifier(llm, "llm_ner_cdr")
ed_retrieval = BlinkBiEncoder.from_identifier("blink_bi_encoder_cdr")
ed_retrieval.make_index(use_precomputed_entity_vectors=True)
ed_reranking = LLMED.from_identifier(llm, "llm_ed_cdr")
docre = LLMDocRE.from_identifier(llm, "llm_docre_cdr")
entity_graph_construction = EntityGraphConstructor()
community_clustering = NeighborhoodAggregation(hop_size=1)
report_generation = TemplateBasedReportGenerator()
chunker = Chunker(model_name="en_core_sci_md")
passage_retrieval = Qwen3Embedding(
model_name="Qwen/Qwen3-Embedding-0.6B",
max_passage_length=8192,
normalize=True,
metric="inner-product",
query_instruction="Given a question, retrieve relevant passages that answer the question."
)
qa = LLMQA(
model=llm,
prompt_template_name_or_path="qa_04_with_context",
)
# Instantiate the GraphRAG pipeline
graphrag = GraphRAGPipeline(
ner=ner,
ed_retrieval=ed_retrieval,
ed_reranking=ed_reranking,
docre=docre,
entity_graph_construction=entity_graph_construction,
community_clustering=community_clustering,
report_generation=report_generation,
chunker=chunker,
passage_retrieval=passage_retrieval,
qa=qa,
)
# Build the GraphRAG index
graphrag.make_index(
documents=documents,
index_dir=index_dir,
retrieval_size=10,
window_size=100,
entity_dict=entity_dict,
passage_retrieval_indexing_kwargs={
"batch_size": 64,
},
)
# Load the GraphRAG index
graphrag.load_index(index_dir=index_dir)
# Answer questions using the GraphRAG index
answers = graphrag.infer(
questions=questions,
top_k=5,
)
# Save the results
utils.write_json("./predictions.json", answers)
The components can also be used independently. Please see the corresponding documentation for each component for more details.
Citation / Publication
If KAPipe is helpful for your work, please consider citing the following paper:
Dissecting GraphRAG: A Modular Analysis of Knowledge Structuring for Factoid Question Answering. Noriki Nishida, Rumana Ferdous Munne, Shanshan Liu, Narumi Tokunaga, Yuki Yamagata, Fei Cheng, Kouji Kozaki, and Yuji Matsumoto. Transactions of the Association for Computational Linguistics (TACL), vol. 14, pp. 627-655. 2026. (Presented at ACL 2026)
@article{nishida-etal-2026-dissecting,
title = "Dissecting {G}raph{RAG}: A Modular Analysis of Knowledge Structuring for Factoid Question Answering",
author = "Nishida, Noriki and
Munne, Rumana Ferdous and
Liu, Shanshan and
Tokunaga, Narumi and
Yamagata, Yuki and
Cheng, Fei and
Kozaki, Kouji and
Matsumoto, Yuji",
journal = "Transactions of the Association for Computational Linguistics",
volume = "14",
year = "2026",
address = "Cambridge, MA",
publisher = "MIT Press",
url = "https://aclanthology.org/2026.tacl-1.29/",
doi = "10.1162/tacl.a.615",
pages = "627--655"
}
Release files for kapipe 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kapipe-0.3.0.tar.gz | 187.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kapipe-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 431.5 kB
Release files / kapipe-0.3.0.tar.gz
| Download URL | kapipe-0.3.0.tar.gz |
|---|---|
| Size | 187.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
542365c22bb974617645e6ed2e4058a9394a5ff4051a3ce6bf82c2f390573647
|
|
BLAKE2b-256 checksum How to use checksums |
8c6ee5479c690f180cb5b70865b18f04332ce339405babd9e07708f023ff5a6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / kapipe-0.3.0-py3-none-any.whl
| Download URL | kapipe-0.3.0-py3-none-any.whl |
|---|---|
| Size | 243.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3e9e9d5041e9c880391b62bf3bd3f7d67022286fea0eb5d5af25b6e432ac8366
|
|
BLAKE2b-256 checksum How to use checksums |
ebf7d3e61cd8933b75a1381ec4b43a3b608120d8695128d054a24ce6732a0a5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|