CDD Blog Technical Documentation

website·Indexed 30 days ago

https://cdd-blog.pages.dev

A technical knowledge base covering Java development, Spring framework (including Spring Boot and Spring AI 1.0.0-SNAPSHOT), Spring Cloud, and LLM implementation. It includes guides on Retrieval-Augmented Generation (RAG), LlamaIndex 0.10.17, Streamlit 1.38, RabbitMQ, and JavaWeb fundamentals with MySQL and JDBC.

Tokens
40.8K
Snippets
149
Records
224
Agent score
75%

What's inside CDD Blog

  1. Identify RAG downstream tasks and applications

    While Question Answering (QA) is the primary task for RAG (including single-hop, multi-hop, and domain-specific QA), the framework is applicable to several other downstream tasks:

    • Information Extraction (IE): Extracting structured data from unstructured text.
    • Dialogue Generation: Enhancing conversational agents with external knowledge.
    • Code Search: Retrieving relevant code snippets to assist in generation or debugging.
  2. Understand RabbitMQ Core Architecture

    RabbitMQ uses a decoupled architecture where producers do not send messages directly to queues, but instead send them to an Exchange.

    Key components include:

    • Publisher: Sends messages to an Exchange.
    • Exchange: Receives messages from publishers and routes them to queues based on the exchange type and routing rules. Exchanges do not store messages; if no queue is bound or no routing rule matches, the message is lost.
    • Queue: Receives and buffers messages. Queues must be bound to an exchange to receive data.
    • Consumer: Subscribes to a queue to process messages.
  3. Implement a basic RAG workflow with LangChain

    Retrieval-Augmented Generation (RAG) addresses LLM limitations such as bias, hallucinations, and outdated knowledge by augmenting the prompt with relevant context from external data sources. The standard workflow involves: 1. Loading data via Document Loaders, 2. Splitting text into chunks, 3. Vectorizing text using embedding models, 4. Storing vectors in a Vector Database, and 5. Retrieving similar context based on a user query to provide as a prompt to the LLM.
  4. Implement Modular RAG for flexible LLM applications

    Modular RAG provides a highly flexible architecture where components can be replaced or reconfigured. It introduces specialized modules to handle complex retrieval and processing tasks:

    • Search Module: Uses LLM-generated code or query languages to search across diverse sources like search engines, databases, and knowledge graphs.
    • RAGFusion: Employs a multi-query strategy to expand a user query from different perspectives, using parallel vector searches and intelligent reranking.
    • Memory Module: Uses a memory pool and iterative self-enhancement to align text more closely with data distributions.
    • Routing Module: Navigates different data sources to select the optimal path for a query (e.g., choosing between a summary, a specific database search, or merged streams).
    • Prediction Module: Generates context directly via the LLM to reduce noise and redundancy.
    • Task Adapter Module: Adapts the RAG system to downstream tasks via automated prompt retrieval or few-shot query generation.
  5. Understand the RAG System Architecture

    A Retrieval-Augmented Generation (RAG) system consists of two core modules: a Retriever and a Generator. The workflow follows these steps: 1. The Retriever receives an input query and searches for relevant information from a data store. 2. The original query and the retrieved results are combined using specific augmentation methods. 3. The Generator processes this augmented input to produce the final result.
  6. Use Ray Dataset for large-scale RAG data management

    Ray Dataset is recommended for building and managing large distributed datasets in RAG pipelines. It leverages Ray's parallel computing to accelerate loading, processing, and querying. It supports formats like CSV, JSON, and TFRecord, and provides capabilities for filtering, transformation, and aggregation.
  7. Understand the Naive RAG workflow

    Naive RAG follows a linear 'Retrieve-Read' framework consisting of three primary stages:

    1. Indexing: An offline process where raw data (PDF, HTML, Word, Markdown) is cleaned, converted to plain text, split into smaller chunks to fit LLM context limits, converted into vector embeddings via an embedding model, and stored in a vector database as key-value pairs.
    2. Retrieval: The system converts a user query into a vector using the same embedding model and retrieves the top-K most similar chunks from the vector database based on similarity scores.
    3. Generation: The original query and the retrieved chunks are synthesized into a prompt for the LLM, which generates a response based on the provided context and its internal knowledge.
  8. Implement LongRAG to improve RAG performance with long-context LLMs

    LongRAG is a framework designed to overcome the limitations of traditional RAG, where short retrieval units (e.g., 100-word paragraphs) often lead to loss of context and the introduction of hard negative samples. LongRAG utilizes a 'long retriever' and 'long reader' approach, processing data into significantly larger units (e.g., 4K token units for Wikipedia, which are 30x longer than traditional units). This reduces the total number of units the retriever must search, preserves semantic integrity, and leverages the capabilities of long-context LLMs for zero-shot answer generation without requiring additional training. It has demonstrated strong performance on datasets such as NQ, HotpotQA, Qasper, and MultiFieldQA-en.
  9. Understand Spring Framework Core Architecture

    The Spring Framework is organized into several key layers:

    • Core Container: The central module that all other modules depend on.
    • AOP (Aspect Oriented Programming): Used for enhancing functionality without modifying original code. Aspects is the concrete implementation of AOP.
    • Data Layer: Includes Data Access (concrete implementation of data access), Data Integration (integration with other solutions like MyBatis), and Transactions (implemented via Spring AOP).
    • Web Layer: Handled by SpringMVC.
    • Test Layer: Primarily integrates with JUnit for unit and integration testing.
  10. Understand RabbitMQ Core Architecture

    RabbitMQ uses a routing model where messages are not sent directly to queues but through an exchange.

    Key components include:

    • Publisher: The entity that sends messages.
    • Consumer: The entity that receives and processes messages.
    • Queue: Stores messages until they are processed by a consumer.
    • Exchange: Responsible for routing messages from the publisher to the appropriate queue(s).
    • Virtual Host (vhost): Provides logical data isolation. Each vhost is independent and contains its own exchanges and queues.
  11. Implement Speculative RAG

    Speculative RAG focuses on resource efficiency and response speed by replacing pure generation with retrieval where possible. Key strategies include:

    • Using retrieval to replace small models in speculative decoding for draft generation.
    • Implementing semantic caching (e.g., GPTCache) to store and reuse LLM responses to reduce API latency.
    • Decomposing generation into 'copy and paste' operations, retrieving exact phrases from documents instead of generating them token-by-token.
  12. Implement a Service using Mybatis-Plus ServiceImpl

    To implement a service layer in Mybatis-Plus, extend ServiceImpl<Mapper, Entity> and implement your custom service interface. This provides access to the baseMapper and built-in CRUD methods (like getById, updateById) directly within the service class without needing to manually inject the mapper.
    @Service
    public class IUserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
        // userMapper is available via baseMapper inherited from ServiceImpl
        
        @Override
        public String deductBalance(Long id, Integer money) {
            User user = selectById(id); // Built-in method from ServiceImpl
            if(user == null) return "User not found";
            
            user.setBalance(user.getBalance() - money);
            updateById(user); // Built-in method from ServiceImpl
            return "Success";
        }
    }