You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/retrieval-augmented-generation/rag-repo.md
+32-33Lines changed: 32 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# New repository for RAG
1
+
# Code location for RAG
2
2
3
3
| Created | Dec 5, 2024 |
4
4
| -------- | -------- |
@@ -17,60 +17,57 @@ Many InstructLab users want to train a model and then use it to RAG. Often they
17
17
- Building their own RAG is extra work.
18
18
- Users who are not experts on RAG might not build a RAG that provides outstanding results.
19
19
20
-
There is a very simple RAG capability at <https://github.com/instructlab/rag> . It is not tightly integrated with InstructLab and it does not use any advanced RAG capabilities. However, it might have some existing users so we can't just unilaterally delete it or replace it with something radically different.
20
+
There is a very simple RAG capability at <https://github.com/instructlab/rag> . It is not tightly integrated with InstructLab and it does not use any advanced RAG capabilities. However, we have a directive from product management to not just unilaterally delete it or replace it with something radically different.
21
21
22
22
## Goals
23
23
24
-
Provide a built-in alternative for users who do not want to build their own RAG. Do not break the existing capability at <https://github.com/instructlab/rag> .
24
+
Provide a built-in alternative for users who do not want to build their own RAG. Keep the existing capability at <https://github.com/instructlab/rag>somewhere, but potentially somewhere other than it is now (e.g., in a new branch of the existing repository).
25
25
26
26
## Non-goals
27
27
28
28
Evaluation of RAG will be addressed in one or more other development documents. That topic is out of scope for this document.
29
29
30
30
## Decision
31
31
32
-
- There will be a new repository for RAG.
33
-
- It will be located at <https://github.com/instructlab/retrieve>
34
-
- By mid-January, it will be available and working but not integrated with InstructLab.
35
-
- By mid-March, it will be integrated with InstructLab with the new repository being invoked by the core repository and maybe also by the SDG repository.
36
-
- Eventually, it will be integrated with InstructLab with the new repository being invoked only by the core repository.
32
+
- For now, RAG will be located in the core repository in its own directory: `src/instructlab/rag` in the core InstructLab repository (<https://github.com/instructlab/instructlab>).
37
33
38
34
## How
39
35
40
-
### By mid-January
36
+
### Phase 1
41
37
42
-
- There will be a new repository for RAG.
43
-
- It will be located at <https://github.com/instructlab/retrieve>
44
-
- It will *not* be referenced by any other InstructLab repositories at that time.
45
-
- We will provide a sample Python notebook that *at least* shows how to use this repository to do both of the following:
46
-
- After someone has run `ilab data generate`, the code in the notebook pulls extracted content from documents that were stored during the execution of that command and indexes that content in a vector database. (Note that this will also require updates to the SDG code base to ensure that the extracted content is stored; currently only the legacy format Docling outputs are stored.)
47
-
- The code in the notebook takes a session history plus a query and does both retrieval and response generation to produce answers (i.e., run-time RAG). That code shows how to do this both with an unmodified open-source LLM for response generation *and* with an InstructLab fine-tuned LLM to compare before-and-after fine-tuning behavior.
38
+
- RAG will be located in the core repository in its own directory: `src/instructlab/rag` in the core InstructLab repository (<https://github.com/instructlab/instructlab>).
39
+
- This directory will include all of the following:
40
+
- Loading the content from docling-format JSON files (that are produced by SDG preprocessing).
41
+
- Chunking that content to sizes that fit the requirements of the selected embedding model for vector database storage and retrieval.
42
+
- Storing those chunks with their vector representations in a vector database.
43
+
- End-to-end runtime RAG. The initial version of this includes the following:
44
+
- Taking as input a session history (including a current user query) and providing a response (e.g., something along the lines of the [OpenAI chat completion API](https://platform.openai.com/docs/api-reference/chat/create)).
45
+
- During that processing, it retrieves relevant search results from the vector database, it converts those into a prompt to send to the response generation model, it prompts that model, and it returns the response from that model.
46
+
- This will be invoked from the existing `ilab` CLI, as described in the [RAG ingestion and chat pipelines](https://github.com/instructlab/dev-docs/pull/161) dev doc.
48
47
49
-
### By mid-March
48
+
### Future phases
50
49
51
-
- The capabilities in `retrieve` will be improved with more advanced functionality. (Details TBD)
52
-
- The InstructLab command-line interface will be updated as follows:
53
-
- There will be one or more commands that can be configured to index content in a vector database. Those commands will call out to `retrieve` to do this indexing.
54
-
- The existing chat capability will be configurable to either use RAG (which would involve calling out to `retrieve`) or not use RAG (which would provide the current behavior).
55
-
- Both indexing and run-time RAG will be implemented by calls that go directly from the core repo (`instructlab/instructlab`) to `retrieve`*unless* the work to migrate SDG preprocessing to the core repo is not complete by then (in which case there may need to be calls from SDG to `retrieve` until the migration completes).
56
-
57
-
### Beyond mid-March
58
-
59
-
- The capabilities in `retrieve` will continue to be improved with even more advanced functionality. (Details TBD)
60
-
- Both indexing and run-time RAG will be implemented by calls that go directly from the core repo to `retrieve`. The SDG repository will not directly invoke the retrieve repository since the document processing will all be done in the core repository and the outputs of that document processing will be consumed by both `retrieve` and SDG.
50
+
- In the near future, RAG might be moved to the existing <https://github.com/instructlab/rag> repository.
51
+
- If so, something will be done with the existing code in <https://github.com/instructlab/rag>, e.g., moving it to a branch of that repository or moving it to a different repository.
52
+
- Alternatively, some or all of it might move to a new repository.
53
+
- For example, maybe the indexing and retrieval portions move to a separate retrieval repository while the rest of end-to-end runtime RAG might move somewhere else.
54
+
- If/when we move ahead with any of these options, *we will open a new ADR for that decision*.
55
+
- Also, the capabilities will keep improving and adding more functionality.
61
56
62
57
## Alternatives
63
58
59
+
- Put the indexing and run-time RAG code in a new repository.
60
+
- Pro: Having a dedicated repository gives the RAG team the most freedom and flexibility to make technical decisions that work for that team.
61
+
- Pro: Starting with a new repository provides a blank slate that can be set up in whatever way makes the most sense for that functionality.
62
+
- Pro: Having the capability in one repository makes it easier for consumers such as RamaLama to reuse it for their purposes too.
63
+
- Con: Creating and configuring a new repository is some work. (This is a fairly small con, but a real one.)
64
+
- Con: Integrating a new repository into the continuous integration and delivery capabilities for both upstream InstructLab and downstream consumers is a *lot* of work. This is a much bigger con.
65
+
- Con: All that extra work would almost certainly result in slower time to market. This risks missing some market opportunities.
64
66
- Put the indexing code in <https://github.com/instructlab/sdg> (SDG) and the run-time RAG code in <https://github.com/instructlab/instructlab> (core)
65
67
- Pro: This has the advantage of not adding any new dependencies.
66
68
- Pro: The document processing is already in SDG and chat functionality is already in core so this would require the fewest code changes.
67
69
- Con: Splitting the RAG functionality across multiple repositories makes it more complicated to reuse in other applications outside of InstructLab.
68
70
- Con: Many things we will want to do to add advanced functionality to make RAG more effective will require changes to both indexing and run-time RAG. If those components are split across multiple repositories, that will make delivering such changes more complicated.
69
-
- Put the indexing and run-time RAG code in <https://github.com/instructlab/instructlab> (core)
70
-
- Pro: This has the advantage of not adding any new dependencies.
71
-
- Pro: However, since the existing document processing is in SDG, the flow for indexing for RAG would be a bit complicated (i.e., it starts with a CLI call handled by the core repo then goes to SDG for some of the document processing and then back to the core for vector database indexing). That drawback will be eliminated if/when the document processing moves into the core repository.
72
-
- Con: Putting the RAG functionality in the core repository requires any application that wants to use this functionality to bring in the entire core which then brings in all of the libraries it depend on, so this becomes an enormous dependency. This would discourage reuse in other applications.
73
-
- Con: Building a great RAG capability is a long-term grand challenge that will require a lot of dedicated investment. That makes it a poor fit for a repository that also has a lot of existing responsibilities.
74
71
- Start by putting the code into existing InstructLab repositories (either of the above options) and then split if off into its own repository later.
75
72
- Pro: Gets us integrated into InstructLab sooner.
76
73
- Con: Adds extra work to the second phase where we have to split it off into its own repository.
@@ -99,9 +96,11 @@ Evaluation of RAG will be addressed in one or more other development documents.
99
96
100
97
## Risks
101
98
102
-
- Adding a new repo and dependencies adds more continuous integration complexity and work.
103
-
- That extra work is why we're not planning calls from InstructLab core to the RAG capability until the mid-March time frame. This risks missing some market opportunities.
99
+
- Putting the RAG functionality in the core repository requires any application that wants to use this functionality to bring in the entire core which then brings in all of the libraries it depend on, so this becomes an enormous dependency. This discourages reuse in other applications. It *encourages* either of the following behaviors that would be unfortunate:
100
+
- Other applications pull directly from <https://github.com/redhat-et/PaRAGon> and in doing so duplicate the ongoing effort to harden/productize that code base.
101
+
- Other applications may implement their own RAG solutions or pull from some other upstream unrelated to ours.
104
102
- As noted earlier, putting the capability inside <https://github.com/instructlab/> signals that this is a component of InstructLab and not a generally useful feature. That creates a risk that the work could miss out on additional opportunities for impact. We hope to mitigate that risk by spinning it off to its own open source project when it is mature enough, but there is a risk that we will get distracted by other things and never get around to this.
103
+
- The flow for document processing for InstructLab winds up being quite complicated in this proposal. Since the existing document processing is in SDG, the flow for indexing for RAG winds up being a bit complicated (i.e., it starts with a CLI call handled by the core repo then goes to SDG for some of the document processing and then back to the core `/data` directory which then calls out the the `core/rag` directory for chunking and vector database indexing). Having the document processing move from core to SDG and back to core and forward to RAG makes that capability more difficult to understand and maintain. This complexity will be partially mitigated when the preprocessing code moves from SDG to core. It will be further mitigated by having a clear, well-documented contract between core and the RAG repository indicating the responsibilities of each.
0 commit comments