# K-RagRec

A PyTorch implementation, from an ACL paper, of knowledge-graph retrieval-augmented generation for LLM-based recommendation, evaluated on MovieLens and Amazon Book datasets.

K-RagRec is the official research code for a paper on using knowledge-graph retrieval to improve large-language-model-based recommendation. It processes a knowledge graph for a chosen dataset, builds corresponding knowledge vector databases, retrieves relevant knowledge sub-graphs for a given user or item, re-ranks them, and feeds the result into a graph-aware LLM recommender for training and evaluation.

The repository provides training and evaluation scripts with configurable parameters such as the adaptive ratio, number of retrieved sub-graphs and number of re-ranked sub-graphs, and ships processed data and knowledge graphs for MovieLens-1M, with raw data provided for MovieLens-20M and Amazon Book so they can be processed the same way. Experiments were run on two NVIDIA A6000 GPUs, with a separate code path provided for a single-GPU setup; it requires Python 3.9 with specific pinned versions of PyTorch, Transformers, NetworkX and PEFT.

Website: https://github.com/Sjay-Wang/K-ragrec
