retrieval_augmented_generation.md 2.75 KB
Newer Older
1
# Retrieval-Augmented Generation
2
3
4
5

[Retrieval-augmented generation (RAG)](https://en.wikipedia.org/wiki/Retrieval-augmented_generation) is a technique that enables generative artificial intelligence (Gen AI) models to retrieve and incorporate new information. It modifies interactions with a large language model (LLM) so that the model responds to user queries with reference to a specified set of documents, using this information to supplement information from its pre-existing training data. This allows LLMs to use domain-specific and/or updated information. Use cases include providing chatbot access to internal company data or generating responses based on authoritative sources.

Here are the integrations:
6

7
8
9
10
11
12
13
- vLLM + [langchain](https://github.com/langchain-ai/langchain) + [milvus](https://github.com/milvus-io/milvus)
- vLLM + [llamaindex](https://github.com/run-llama/llama_index) + [milvus](https://github.com/milvus-io/milvus)

## vLLM + langchain

### Prerequisites

14
Set up the vLLM and langchain environment:
15

16
```bash
17
18
19
20
21
22
23
24
pip install -U vllm \
            langchain_milvus langchain_openai \
            langchain_community beautifulsoup4 \
            langchain-text-splitters
```

### Deploy

25
1. Start the vLLM server with the supported embedding model, e.g.
26

27
28
29
30
    ```bash
    # Start embedding service (port 8000)
    vllm serve ssmits/Qwen2-7B-Instruct-embed-base
    ```
31

32
1. Start the vLLM server with the supported chat completion model, e.g.
33

34
35
36
37
    ```bash
    # Start chat service (port 8001)
    vllm serve qwen/Qwen1.5-0.5B-Chat --port 8001
    ```
38

39
1. Use the script: [examples/online_serving/retrieval_augmented_generation_with_langchain.py](../../../examples/online_serving/retrieval_augmented_generation_with_langchain.py)
40

41
1. Run the script
42

43
    ```bash
44
45
    python retrieval_augmented_generation_with_langchain.py
    ```
46
47
48
49
50

## vLLM + llamaindex

### Prerequisites

51
Set up the vLLM and llamaindex environment:
52

53
```bash
54
55
56
57
58
59
60
61
62
pip install vllm \
            llama-index llama-index-readers-web \
            llama-index-llms-openai-like    \
            llama-index-embeddings-openai-like \
            llama-index-vector-stores-milvus \
```

### Deploy

63
1. Start the vLLM server with the supported embedding model, e.g.
64

65
66
67
68
    ```bash
    # Start embedding service (port 8000)
    vllm serve ssmits/Qwen2-7B-Instruct-embed-base
    ```
69

70
1. Start the vLLM server with the supported chat completion model, e.g.
71

72
73
74
75
    ```bash
    # Start chat service (port 8001)
    vllm serve qwen/Qwen1.5-0.5B-Chat --port 8001
    ```
76

77
1. Use the script: [examples/online_serving/retrieval_augmented_generation_with_llamaindex.py](../../../examples/online_serving/retrieval_augmented_generation_with_llamaindex.py)
78

79
1. Run the script:
80

81
    ```bash
82
83
    python retrieval_augmented_generation_with_llamaindex.py
    ```