# rucaibox/lc-rec architecture

> Architecture diagram of the GitHub repository rucaibox/lc-rec, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rucaibox/lc-rec
- Repository: https://github.com/rucaibox/lc-rec

## Overview

LC-Rec combines collaborative item indexing with LLM alignment tuning for recommendation. The documented workflow prepares Amazon interaction data and item features, learns quantized item indices, then uses task-specific prompts and datasets to fine-tune an LLM and run recommendation tests. The graph preserves the README’s task families and conversion-based checkpoint workflow; several links rely on README or index references because runtime entry-point excerpts were not provided.

Main entry points: [`data.py`](https://github.com/rucaibox/lc-rec/blob/main/data.py) (Task datasets), [`index/models/rqvae.py`](https://github.com/rucaibox/lc-rec/blob/main/index/models/rqvae.py) (Residual quantizer), [`test.py`](https://github.com/rucaibox/lc-rec/blob/main/test.py) (Recommendation inference), [`index/generate_indices.py`](https://github.com/rucaibox/lc-rec/blob/main/index/generate_indices.py) (Index generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Data preparation"]
  node_amazon_process["Amazon processing"]
  node_recbole_process["RecBole processing"]
  node_feature_process["Text embeddings<br/>[amazon_text_emb.py]"]
  node_llm_outputs["Preference outputs<br/>[get_llm_output.py]"]
end

subgraph group_index["Item indexing"]
  node_index_data["Embedding dataset<br/>[datasets.py]"]
  node_index_runner["Index training<br/>[main.py]"]
  node_index_trainer["Index trainer<br/>[trainer.py]"]
  node_rqvae["Residual quantizer<br/>[rqvae.py]"]
  node_mlp["Encoder layers<br/>[layers.py]"]
  node_residual_vq["Residual VQ<br/>[rq.py]"]
  node_vector_quantizer["Vector quantizer<br/>[vq.py]"]
  node_index_generator["Index generation"]
  node_item_indices["Item indices"]
end

subgraph group_llm["LLM recommendation"]
  node_task_data["Task datasets<br/>[data.py]"]
  node_prompt_templates["Task prompts<br/>[prompt.py]"]
  node_collator["Batch collation<br/>[collator.py]"]
  node_finetuning["Alignment tuning<br/>[finetune.py]"]
  node_lora["LoRA tuning<br/>[lora_finetune.py]"]
  node_testing["Recommendation inference<br/>[test.py]"]
  node_ddp_testing["Distributed inference<br/>[test_ddp.py]"]
end

subgraph group_checkpoint["Model artifacts"]
  node_checkpoint_conversion["Checkpoint conversion<br/>[convert.py]"]
  node_delta_merge["Delta merge<br/>[merge_delta.py]"]
  node_model_checkpoint["LC-Rec weights"]
end

node_data_source["Dataset files"]
node_user(("Recommendation user"))
node_base_model["Base LLM"]
node_results["Recommendation results"]

node_data_source -->|"processes"| node_amazon_process
node_data_source -.->|"processes"| node_recbole_process
node_data_source -.->|"embeds text"| node_feature_process
node_data_source -->|"generates preferences"| node_llm_outputs
node_feature_process -.->|"provides embeddings"| node_index_data
node_index_data -->|"loads batches"| node_index_runner
node_index_runner -->|"constructs model"| node_rqvae
node_index_runner -->|"trains with"| node_index_trainer
node_index_trainer -->|"optimizes"| node_rqvae
node_rqvae -->|"uses encoder"| node_mlp
node_rqvae -->|"quantizes through"| node_residual_vq
node_residual_vq -->|"uses codebooks"| node_vector_quantizer
node_index_generator -->|"loads embeddings"| node_index_data
node_index_generator -->|"loads model"| node_rqvae
node_index_generator -.->|"writes indices"| node_item_indices
node_task_data -->|"formats tasks"| node_prompt_templates
node_item_indices -->|"loads indices"| node_task_data
node_llm_outputs -.->|"supplies preferences"| node_task_data
node_task_data -->|"batches examples"| node_collator
node_collator -->|"prepares inputs"| node_finetuning
node_finetuning -.->|"tunes"| node_base_model
node_lora -.->|"adapts"| node_base_model
node_user -.->|"requests recommendation"| node_testing
node_testing -->|"loads test examples"| node_task_data
node_testing -.->|"generates with"| node_base_model
node_ddp_testing -->|"loads test examples"| node_task_data
node_testing -.->|"writes predictions"| node_results
node_ddp_testing -.->|"writes predictions"| node_results
node_finetuning -.->|"converts checkpoint"| node_checkpoint_conversion
node_checkpoint_conversion -.->|"produces weights"| node_model_checkpoint
node_model_checkpoint -->|"applies delta to base"| node_delta_merge
node_delta_merge -->|"loads base weights"| node_base_model
node_delta_merge -->|"writes merged weights"| node_model_checkpoint

click node_amazon_process "https://github.com/rucaibox/lc-rec/blob/main/data_process/amazon18_data_process.py"
click node_recbole_process "https://github.com/rucaibox/lc-rec/blob/main/data_process/amazon18_recbole_data_process.py"
click node_feature_process "https://github.com/rucaibox/lc-rec/blob/main/data_process/amazon_text_emb.py"
click node_llm_outputs "https://github.com/rucaibox/lc-rec/blob/main/data_process/get_llm_output.py"
click node_index_data "https://github.com/rucaibox/lc-rec/blob/main/index/datasets.py"
click node_index_runner "https://github.com/rucaibox/lc-rec/blob/main/index/main.py"
click node_index_trainer "https://github.com/rucaibox/lc-rec/blob/main/index/trainer.py"
click node_rqvae "https://github.com/rucaibox/lc-rec/blob/main/index/models/rqvae.py"
click node_mlp "https://github.com/rucaibox/lc-rec/blob/main/index/models/layers.py"
click node_residual_vq "https://github.com/rucaibox/lc-rec/blob/main/index/models/rq.py"
click node_vector_quantizer "https://github.com/rucaibox/lc-rec/blob/main/index/models/vq.py"
click node_index_generator "https://github.com/rucaibox/lc-rec/blob/main/index/generate_indices.py"
click node_task_data "https://github.com/rucaibox/lc-rec/blob/main/data.py"
click node_prompt_templates "https://github.com/rucaibox/lc-rec/blob/main/prompt.py"
click node_collator "https://github.com/rucaibox/lc-rec/blob/main/collator.py"
click node_finetuning "https://github.com/rucaibox/lc-rec/blob/main/finetune.py"
click node_lora "https://github.com/rucaibox/lc-rec/blob/main/lora_finetune.py"
click node_testing "https://github.com/rucaibox/lc-rec/blob/main/test.py"
click node_ddp_testing "https://github.com/rucaibox/lc-rec/blob/main/test_ddp.py"
click node_checkpoint_conversion "https://github.com/rucaibox/lc-rec/blob/main/convert/convert.py"
click node_delta_merge "https://github.com/rucaibox/lc-rec/blob/main/convert/merge_delta.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_amazon_process,node_recbole_process,node_feature_process,node_llm_outputs,node_user toneBlue
class node_index_data,node_index_runner,node_index_trainer,node_rqvae,node_mlp,node_residual_vq,node_vector_quantizer,node_index_generator,node_item_indices toneAmber
class node_task_data,node_prompt_templates,node_collator,node_finetuning,node_lora,node_testing,node_ddp_testing toneMint
class node_checkpoint_conversion,node_delta_merge,node_model_checkpoint toneRose
class node_data_source,node_base_model,node_results toneIndigo
```

## Components

### Data preparation

- [Amazon processing](https://github.com/rucaibox/lc-rec/blob/main/data_process/amazon18_data_process.py): `data_process/amazon18_data_process.py`
- [RecBole processing](https://github.com/rucaibox/lc-rec/blob/main/data_process/amazon18_recbole_data_process.py): `data_process/amazon18_recbole_data_process.py`
- [Text embeddings](https://github.com/rucaibox/lc-rec/blob/main/data_process/amazon_text_emb.py): `data_process/amazon_text_emb.py`
- [Preference outputs](https://github.com/rucaibox/lc-rec/blob/main/data_process/get_llm_output.py): `data_process/get_llm_output.py`

### Item indexing

- [Embedding dataset](https://github.com/rucaibox/lc-rec/blob/main/index/datasets.py): `index/datasets.py`
- [Index training](https://github.com/rucaibox/lc-rec/blob/main/index/main.py): `index/main.py`
- [Index trainer](https://github.com/rucaibox/lc-rec/blob/main/index/trainer.py): `index/trainer.py`
- [Residual quantizer](https://github.com/rucaibox/lc-rec/blob/main/index/models/rqvae.py): `index/models/rqvae.py`
- [Encoder layers](https://github.com/rucaibox/lc-rec/blob/main/index/models/layers.py): `index/models/layers.py`
- [Residual VQ](https://github.com/rucaibox/lc-rec/blob/main/index/models/rq.py): `index/models/rq.py`
- [Vector quantizer](https://github.com/rucaibox/lc-rec/blob/main/index/models/vq.py): `index/models/vq.py`
- [Index generation](https://github.com/rucaibox/lc-rec/blob/main/index/generate_indices.py): `index/generate_indices.py`
- **Item indices**

### LLM recommendation

- [Task datasets](https://github.com/rucaibox/lc-rec/blob/main/data.py): `data.py`
- [Task prompts](https://github.com/rucaibox/lc-rec/blob/main/prompt.py): `prompt.py`
- [Batch collation](https://github.com/rucaibox/lc-rec/blob/main/collator.py): `collator.py`
- [Alignment tuning](https://github.com/rucaibox/lc-rec/blob/main/finetune.py): `finetune.py`
- [LoRA tuning](https://github.com/rucaibox/lc-rec/blob/main/lora_finetune.py): `lora_finetune.py`
- [Recommendation inference](https://github.com/rucaibox/lc-rec/blob/main/test.py): `test.py`
- [Distributed inference](https://github.com/rucaibox/lc-rec/blob/main/test_ddp.py): `test_ddp.py`

### Model artifacts

- [Checkpoint conversion](https://github.com/rucaibox/lc-rec/blob/main/convert/convert.py): `convert/convert.py`
- [Delta merge](https://github.com/rucaibox/lc-rec/blob/main/convert/merge_delta.py): `convert/merge_delta.py`
- **LC-Rec weights**

### Other components

- **Dataset files**
- **Recommendation user**
- **Base LLM**
- **Recommendation results**

## Connections

- Dataset files → Amazon processing: processes (evidence: `data_process/amazon18_data_process.py`)
- Dataset files → RecBole processing: processes
- Dataset files → Text embeddings: embeds text
- Dataset files → Preference outputs: generates preferences (evidence: `data_process/get_llm_output.py`)
- Text embeddings → Embedding dataset: provides embeddings
- Embedding dataset → Index training: loads batches (evidence: `index/main.py`)
- Index training → Residual quantizer: constructs model (evidence: `index/main.py`)
- Index training → Index trainer: trains with (evidence: `index/main.py`)
- Index trainer → Residual quantizer: optimizes (evidence: `index/trainer.py`)
- Residual quantizer → Encoder layers: uses encoder (evidence: `index/models/rqvae.py`)
- Residual quantizer → Residual VQ: quantizes through (evidence: `index/models/rqvae.py`)
- Residual VQ → Vector quantizer: uses codebooks (evidence: `index/models/rq.py`)
- Index generation → Embedding dataset: loads embeddings (evidence: `index/generate_indices.py`)
- Index generation → Residual quantizer: loads model (evidence: `index/generate_indices.py`)
- Index generation → Item indices: writes indices
- Task datasets → Task prompts: formats tasks (evidence: `data.py`)
- Item indices → Task datasets: loads indices (evidence: `data.py`)
- Preference outputs → Task datasets: supplies preferences
- Task datasets → Batch collation: batches examples
- Batch collation → Alignment tuning: prepares inputs (evidence: `finetune.py`)
- Alignment tuning → Base LLM: tunes
- LoRA tuning → Base LLM: adapts
- Recommendation user → Recommendation inference: requests recommendation
- Recommendation inference → Task datasets: loads test examples
- Recommendation inference → Base LLM: generates with
- Distributed inference → Task datasets: loads test examples
- Recommendation inference → Recommendation results: writes predictions
- Distributed inference → Recommendation results: writes predictions
- Alignment tuning → Checkpoint conversion: converts checkpoint (evidence: `README.md`)
- Checkpoint conversion → LC-Rec weights: produces weights
- LC-Rec weights → Delta merge: applies delta to base (evidence: `README.md`)
- Delta merge → Base LLM: loads base weights (evidence: `README.md`)
- Delta merge → LC-Rec weights: writes merged weights (evidence: `README.md`)
