nv-morpheus / Morpheus

Morpheus SDK
Apache License 2.0
369 stars 140 forks source link

Create Sherlock example for Retrieval Augmented Generation (RAG) pipeline #1306

Closed mdemoret-nv closed 11 months ago

mdemoret-nv commented 1 year ago

Is this a new feature, an improvement, or a change to existing functionality?

New Feature

How would you describe the priority of this feature request

High

Please provide a clear description of problem this feature solves

As part of the Sherlock work, an example showing how to use Morpheus to execute multiple LLM queries that utilize RAG inside of a pipeline.

Describe your ideal solution

Purpose

The purpose of this example is to illustrate how a user could build a pipeline while will integrate an LLM service into a Morpheus pipeline. This example builds on the previous example, #1305, by adding the ability to augment LLM queries with context information from a knowledge base. Appending this context helps improve the responses from the LLM by providing additional background contextual and factual information which the LLM can pull from for its response.

In order for this pipeline to function correctly, a Vector Database must already have been populated with information that can be retrieved. An example of populating a database is illustrated in #1298. This example assumes that pipeline has already been run to completion.

Scenario

This example will show two different implementations of a RAG pipeline but the pipeline and components could be used in many scenarios with different requirements. At a high level, the following illustrates different customization points for this pipeline and the specific choices made for this example:

Implementation

This example will be composed of two different click commands.

Standalone Morpheus pipeline

The standalone Morpheus pipeline is built using the following components:

  1. An InMemorySourceStage to hold the LLM queries in a DataFrame
  2. A DeserializationStage to convert the MessageMeta objects into ControlMessages needed by the LLMEngine
  3. New functionality was added to the DeserializeStage to support ControlMessages and add a default task to each message.
  4. A LLMEngineStage then wraps the core LLMEngine functionality
    1. An ExtracterNode pulls the questions out of the DataFrame
    2. A RAGNode performs the retrieval and adds the context to the query using the supplied template and executes the LLM
    3. Finally, the responses are put back into the ControlMessage using a SimpleTaskHandler
  5. The pipeline concludes with an InMemorySink stage to store the results.

Note: For this to function correctly, the VDB upload pipeline must have been run previously.

Persistent Morpheus pipeline

The persistent Morpheus pipeline is functionally similar to the standalone pipeline, however it uses multiple sources and multiple sinks to perform both the upload and retrieval portions in the same pipeline. The benefit of this pipeline over the standalone pipeline is no VDB upload process needed to be run beforehand. Everything runs in a single pipeline.

The implementation for this pipeline is illustrated by the following diagram:

image

The major differences between the diagram and the example pipeline are:

Completion Criteria

The following items need to be satisfied to consider this issue complete:

Dependent Issues

The following issues should be resolved before this can be completed:

- [ ] #1178 
- [ ] #1179 
- [ ] #1272
- [ ] #1277
- [ ] #1278 
- [ ] #1279 
- [ ] #1282 
- [ ] #1301
- [ ] #1302 
- [ ] #1303 
- [ ] #1304

Additional context

No response

Code of Conduct

mdemoret-nv commented 11 months ago

Created issue https://github.com/nv-morpheus/Morpheus/issues/1416 to contain the persistent pipeline pieces. Closing this issue.