Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeNaming

AI-assisted Java method naming recommendation system using LLM and RAGFlow.

CodeNaming recommends Java/Spring-style method names from natural language descriptions by analyzing developer intent, retrieving relevant naming knowledge, and evaluating whether generated names preserve the original intent.


1. Overview

Developers often need to convert natural language requirements into clear and consistent method names.

Example

Input

Find active members by email

Output

findActiveMemberByEmail

CodeNaming assists this process by combining:

  • Intent Analysis
  • LLM-based Candidate Generation
  • RAGFlow Knowledge Retrieval
  • Intent Preservation Evaluation
  • Java Naming Convention Validation
  • Caffeine-based Result Caching

The goal is to generate meaningful Java method names while preserving the semantic intention of the original description.


2. Final Architecture

The final system uses a RAG-augmented Two-Call LLM Pipeline.

User Description
        ↓
RAGFlow Knowledge Retrieval
        ↓
Retrieved Knowledge Context
        ↓
Intent Analysis + Candidate Generation
        ↓
Intent Preservation Evaluation
        ↓
Final Method Name Recommendation

RAGFlow acts as a Knowledge Retrieval Layer.

It retrieves relevant knowledge from a prebuilt Dataset and provides the retrieved context to the LLM naming pipeline.

RAGFlow does not directly generate method names and does not automatically analyze the user's project source code.


3. System Evolution

3.1 Initial Architecture: 3-Call Pipeline

The first implementation separated the naming process into three LLM calls.

User Description
        ↓
Intent Analysis
        ↓
Candidate Generation
        ↓
Intent Preservation Evaluation
        ↓
Final Recommendation

Characteristics:

  • Clear separation of responsibilities
  • Independent intent evaluation
  • Higher LLM API usage
  • Higher response latency

3.2 Optimized Architecture: Two-Call Pipeline

Benchmark experiments were used to compare pipeline alternatives.

The architecture was optimized by combining Intent Analysis and Candidate Generation into a single LLM call.

User Description
        ↓
Intent Analysis + Candidate Generation
        ↓
Intent Preservation Evaluation
        ↓
Final Recommendation

Improvements:

  • Reduced LLM calls from 3 to 2
  • Simplified pipeline structure
  • Reduced response latency
  • Reduced external API usage
  • Preserved intent evaluation as an independent stage

3.3 RAG-Augmented Naming Pipeline

After optimizing the LLM pipeline, RAGFlow was integrated as an additional Knowledge Retrieval Layer.

User Description
        ↓
RAGFlow Retrieval
        ↓
Dataset Knowledge Context
        ↓
Two-Call LLM Pipeline
        ↓
Final Recommendation

The retrieved context helps the naming pipeline make recommendations using additional naming-related knowledge instead of relying only on the user description and the LLM's internal knowledge.


4. Core Features

4.1 Natural Language Intent Analysis

The system analyzes a natural language description and extracts its naming intent.

Example:

Find active members by email

The intent can be represented using information such as:

Action:
FIND

Target:
Member

Qualifier:
Active

Condition:
Email

4.2 RAGFlow Knowledge Retrieval

RAGFlow retrieves relevant knowledge from a prebuilt Dataset.

The Dataset contains knowledge such as:

  • Code-related Knowledge
  • Java/Spring Naming Knowledge
  • Naming Patterns

The retrieved knowledge is used as additional context for Method Name Generation.

4.3 Candidate Generation

The first LLM call performs:

Intent Analysis
        +
Candidate Generation

Using both the user description and retrieved knowledge context, the system generates Java-style Method Name candidates.

Example:

findActiveMemberByEmail
findActiveMembersByEmail

4.4 Intent Preservation Evaluation

The second LLM call evaluates whether generated candidates preserve the original developer intent.

Evaluation focuses on:

  • Semantic intent preservation
  • Java Naming Convention
  • Method purpose clarity
  • Naming naturalness

The evaluation stage helps prevent method names that are syntactically valid but semantically inconsistent with the original requirement.

4.5 Caffeine Cache

The system uses Caffeine as an in-memory cache for repeated requests.

When the same description is requested again, the cached result can be returned without repeating the full Retrieval and LLM Pipeline.

Current cache configuration:

Cache Name:
quickNaming

TTL:
10 minutes

Maximum Size:
100 entries

This reduces unnecessary external API calls and improves response time for repeated requests.


5. Technology Stack

Backend

  • Java 21
  • Spring Boot
  • Gradle

AI / LLM

  • Large Language Model API
  • Prompt Engineering
  • Structured Output
  • Intent Preservation Evaluation

Retrieval

  • RAGFlow
  • Knowledge Retrieval
  • Dataset-based Context Augmentation

Performance

  • Caffeine Cache
  • Benchmark-based Pipeline Optimization
  • Latency Measurement

Infrastructure

  • Docker
  • RAGFlow Local Deployment

Frontend

  • HTML
  • CSS
  • JavaScript

6. Benchmark Experiments

The project uses benchmark experiments to support architecture decisions instead of selecting pipeline structures only through subjective judgment.

Experiment 1: 3-Call vs Two-Call Pipeline

Architecture LLM Calls
3-Call Pipeline 3
Two-Call Pipeline 2

Evaluation criteria included:

  • Naming Quality
  • Intent Preservation
  • Response Latency
  • API Call Efficiency

The benchmark results were used to select the Two-Call Pipeline as the final LLM architecture.

Experiment 2: Retrieval Strategy Comparison

Retrieval approaches were also evaluated to examine the effect of adding external Knowledge Context to the naming pipeline.

The experiments include comparison results for lightweight/keyword-based retrieval and RAGFlow-based retrieval.

Evaluation focuses on:

  • Retrieval behavior
  • Naming Quality
  • Response Latency
  • Context utilization

Benchmark source code and result files are included in the repository.


7. Dataset

The RAGFlow Dataset contains Java/Spring-related naming knowledge used by the Retrieval Layer.

Example Dataset entries include:

AuthService_generateToken
AuthService_validateToken
FileService_uploadFile
NotificationService_sendMessage
OrderService_updateStatus
PaymentService_processPayment
PaymentService_refund
ProductService_searchProduct
UserService_changePassword
UserService_createUser
UserService_findUser
UserService_registerUser

These files provide naming-related Knowledge Context that can be retrieved by RAGFlow.


8. Project Structure

CodeNaming_Project/
│
├── CodeNaming/
│   ├── src/
│   │   ├── main/
│   │   │   ├── java/
│   │   │   └── resources/
│   │   └── test/
│   │
│   ├── benchmark/
│   │   ├── BenchmarkRunner.java
│   │   ├── benchmark_dataset.csv
│   │   ├── result_keyword.csv
│   │   └── result_ragflow.csv
│   │
│   ├── docs/
│   ├── gradle/
│   ├── build.gradle
│   ├── settings.gradle
│   ├── gradlew
│   └── gradlew.bat
│
├── dataset/
│   └── RAGFlow knowledge dataset
│
├── experiments/
│   ├── pipeline-comparison/
│   └── retrieval-comparison/
│
├── docs/
│   ├── architecture/
│   └── design-history/
│
├── .env.example
├── .gitignore
└── README.md

9. Main Package Structure

The main backend implementation is organized as follows:

com.codenaming
│
├── component
│   ├── IntentCandidateGenerator
│   ├── IntentPreservationEvaluator
│   └── ...
│
├── config
│   ├── CacheConfig
│   └── LLM configurations
│
├── controller
│   └── QuickNamingController
│
├── dto
│
├── llm
│   ├── LlmClient
│   └── LLM client implementations
│
├── model
│
├── retrieval
│   ├── NamingKnowledgeRetriever
│   ├── KeywordNamingKnowledgeRetriever
│   │
│   └── ragflow
│       ├── RagFlowClient
│       ├── RagFlowNamingKnowledgeRetriever
│       ├── RagFlowProperties
│       └── RagFlowRetrievalConfig
│
├── schema
│
├── service
│   └── NamingService
│
└── validator

10. Environment Configuration

Sensitive API keys are not included in the repository.

Create a local .env file using .env.example as a reference.

ELEX_API_KEY=your_elex_api_key

RAGFLOW_API_KEY=your_ragflow_api_key
RAGFLOW_DATASET_ID=your_dataset_id
RAGFLOW_BASE_URL=http://localhost:9380

CODENAMING_RETRIEVAL_PROVIDER=ragflow

The actual .env file must not be committed to Git.


11. How to Run

11.1 Requirements

Install:

  • Java 21
  • Docker Desktop
  • RAGFlow

11.2 Start RAGFlow

Start the local RAGFlow Docker environment from the RAGFlow Docker directory:

docker compose up -d

Check container status:

docker compose ps

11.3 Configure Environment Variables

Configure the required environment variables using your local .env values.

Required values include:

ELEX_API_KEY
RAGFLOW_API_KEY
RAGFLOW_DATASET_ID
RAGFLOW_BASE_URL
CODENAMING_RETRIEVAL_PROVIDER

11.4 Run CodeNaming

Move to the Spring Boot project directory:

cd CodeNaming

Run the application.

Windows

gradlew.bat bootRun

macOS / Linux

./gradlew bootRun

After the application starts, open:

http://localhost:8080

12. Demo

Example request:

Find active members by email

Processing flow:

Natural Language Description
        ↓
RAGFlow Knowledge Retrieval
        ↓
Retrieved Knowledge Context
        ↓
Intent Analysis + Candidate Generation
        ↓
Intent Preservation Evaluation
        ↓
Method Name Recommendation

Example recommendation:

findActiveMemberByEmail

13. Completed Project Scope

The final implementation includes:

  • MVP Method Naming Recommendation System
  • Initial 3-Call LLM Pipeline
  • Benchmark-based Pipeline Comparison
  • Optimized Two-Call LLM Pipeline
  • Intent Preservation Evaluation
  • Java Naming Convention Validation
  • Lightweight / Keyword Knowledge Retrieval
  • RAGFlow Knowledge Retrieval Integration
  • Dataset-based Context Augmentation
  • Retrieval Benchmark Experiment
  • Caffeine In-memory Cache
  • Spring Boot Web Application
  • Automated Tests

CodeNaming was developed through iterative architecture design, benchmark evaluation, retrieval integration, and performance optimization to produce a completed AI-assisted Java Method Naming Recommendation System.

About

AI-assisted Java method naming recommendation system using Spring Boot, LLM, RAGFlow, and Caffeine Cache.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages