Skip to content

This RAG (Retrieval-Augmented Generation) project is implemented using pure Java. This approach makes it easier to adapt to enterprise-level environments and is more conducive to secondary development.

License

Notifications You must be signed in to change notification settings

ChinaYiqun/java-rag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English | ็ฎ€ไฝ“ไธญๆ–‡

JAVA-RAG

Introduction

RAG (Retrieval - Augmented Generation) project, implemented in pure Java without relying on frameworks like JFinal or spring - boot. It provides the RAG pipeline and Agent pattern, which makes it more convenient to adapt to the enterprise - level environment and more conducive to secondary development.

Quick Start

    public void demoNaiveRAG() {
        NaiveRAG naiveRAG = new NaiveRAG(
                new Document("./202X Enterprise Plan.pdf"),
                "Briefly summarize this article");
        try {
            naiveRAG
                    // Parsing
                   .parsering()
                    // Chunking
                   .chunking()
                    // Vectorization
                   .embedding()
                    // Sorting
                   .sorting()
                    // LLM response
                   .LLMChat();
        } catch (Exception e) {
            e.printStackTrace();
            assert false : "error stack trace";
        }
        System.out.println(naiveRAG.getResponse());
    }

Usage Tutorial

๐Ÿ’ฝ Database Storage

  • Read and write for multi-turn conversations in Redis
  • File storage in MinIO
  • Search engine with Elastic Search
  • OpenAI chat interface
  • Ollama chat interface
  • Chat with multi-turn conversations
  • Word
  • PPT
  • PDF
  • EXCEL
  • PPT
  • Markdown, HTML

โœ‚๏ธ Chunking

  • Fixed size
  • Sentence splitting
  • Recursive splitting
  • Semantic chunking
  • Jina-Cobert
  • Baichuan

๐Ÿ”Ž Search

  • Recall
  • Sorting
  • Re-ranking

๐ŸŽ more pipeline

  • Advanced RAG
  • Modular RAG

๐Ÿฆพ [Agent]

  • MASExample.java

๐ŸŽฐ balance

  • RoundRobinLoadBalancer
  • WeightedRandomLoadBalancer

Project Structure

Explanation

โ”œโ”€โ”€ agent
โ”œโ”€โ”€ chunk
โ”œโ”€โ”€ constant
โ”œโ”€โ”€ controler
โ”œโ”€โ”€ demo
โ”œโ”€โ”€ entity
โ”œโ”€โ”€ parser
โ”œโ”€โ”€ rag
โ”œโ”€โ”€ search
โ”œโ”€โ”€ service
โ”‚   โ”œโ”€โ”€ LLM
โ”‚   โ”œโ”€โ”€ balance
โ”‚   โ”œโ”€โ”€ db
โ”‚   โ””โ”€โ”€ embedding
โ”œโ”€โ”€ utils
โ””โ”€โ”€ web

๐Ÿง’ Concise Installation Tutorial

  1. Clone the code
git clone https://github.com/ChinaYiqun/java-rag.git
  1. Enter the project directory
cd java-rag
  1. Configure Maven dependencies
mvn clean install
  1. Create relevant databases
sysctl -w vm.max_map_count=262144
# Create a docker network
docker network create elastic
# Pull Elasticsearch
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.11.4
# Run Elasticsearch
docker run --name es01 --net elastic -p 9200:9200 -it -m 2GB docker.elastic.co/elasticsearch/elasticsearch:8.11.4
# Reset password and enrollment token
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
# Install MinIO script
mkdir -p ~/minio/data
docker run \ -p 9000:9000 \ -p 9090:9090 \ --name minio \ -v ~/minio/data:/data \ -e "MINIO_ROOT_USER=ROOTNAME" \ -e "MINIO_ROOT_PASSWORD=CHANGEME123" \ quay.io/minio/minio server /data --console-address ":9090"

๐Ÿฅธ Detailed Installation Tutorial

  • See Link for details.

Features

  • OpenAI-style LLM/Embedding interfaces
  • Very simple dependency management with pom.xml (Maven)
  • Support for multi-user and multi-knowledge base management
  • Free arrangement of search strategies: multi-channel recall, rough sorting, fine sorting, re-ranking
  • Free arrangement of file chunking: fixed size, sentence splitting, recursive splitting, semantic chunking
  • Support for mainstream file parsing with Apache POI
  • Integration of mainstream databases: Elastic Search, Redis, Mysql, MinIO
  • Highly customizable configuration with Nacos

view

ezgif-81180eba7adb9d.gif

References

About

This RAG (Retrieval-Augmented Generation) project is implemented using pure Java. This approach makes it easier to adapt to enterprise-level environments and is more conducive to secondary development.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published