Skip to content

Commit 8a7391f

Browse files
committed
Refactored the retrieval chain, and MiniPilot to Minipilot
1 parent 1045c2e commit 8a7391f

File tree

9 files changed

+22
-24
lines changed

9 files changed

+22
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# MiniPilot
1+
# Minipilot
22

33
This application implements a chatbot you can train with your data. From the GUI you will be able to:
44

@@ -16,7 +16,7 @@ The system uses:
1616

1717
## Quickstart
1818

19-
Follow these instructions to build and start MiniPilot and a Redis Stack database as containers on your laptop. For more installation methods, refer to the docs.
19+
Follow these instructions to build and start Minipilot and a Redis Stack database as containers on your laptop. For more installation methods, refer to the docs.
2020

2121
1. `git clone https://github.com/redis/minipilot.git`
2222
2. `export OPENAI_API_KEY="your-openai-key"`

docs/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ The explanation of the steps in the pipeline follows.
1515
7. The question and answer pair is added to the cache if relevant (a basic criterion is represented by the context. If there was at least a result while fetching the context for RAG, then the question is pertinent, and the answer can be saved).
1616
8. The interaction is added to the conversation history.
1717

18-
Regarding the interactions with OpenAI, MiniPilot uses the [chat completion api](https://platform.openai.com/docs/guides/chat-completions) via the LangChain [ChatOpenAI](https://python.langchain.com/v0.2/docs/integrations/chat/openai/) class as well as the `text-embedding-ada-002` embedding model for the retrievers and the semantic cache.
18+
Regarding the interactions with OpenAI, Minipilot uses the [chat completion api](https://platform.openai.com/docs/guides/chat-completions) via the LangChain [ChatOpenAI](https://python.langchain.com/v0.2/docs/integrations/chat/openai/) class as well as the `text-embedding-ada-002` embedding model for the retrievers and the semantic cache.
1919

2020
![architecture](../src/static/images/minipilot-ai-pipeline.png)

docs/faq.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
## What is this?
44

5-
MiniPilot is a GenAI-assisted chatbot. This demo is a minimal implementation (hence the name "MiniPilot"!) which allows you to import data as CSV, process it and store it in a Redis vector database.
6-
You can clone and test the repository, fork it, change the code and, if you like, contribute to the repository. It can be extended to import data from other document formats (like PDF) or crawl and scrape web resources. Ad-hoc connectors can be developed to extend the MiniPilot.
5+
Minipilot is a GenAI-assisted chatbot. This demo is a minimal implementation (hence the name "Minipilot"!) which allows you to import data as CSV, process it and store it in a Redis vector database.
6+
You can clone and test the repository, fork it, change the code and, if you like, contribute to the repository. It can be extended to import data from other document formats (like PDF) or crawl and scrape web resources. Ad-hoc connectors can be developed to extend the Minipilot.
77

8-
## What features can I find in MiniPilot?
8+
## What features can I find in Minipilot?
99

10-
MiniPilot supports:
10+
Minipilot supports:
1111

1212
- Conversation history by session, to make sense of the interactions of a user
1313
- Semantic cache, to store and retrieve past interactions (from all the conversations of all the users). This speeds up the system, because if an answer is in the cache, there is no need to invoke the OpenAI chat endpoint at all.
1414
- Rate limiter, a basic implementation based on Redis
1515
- Configurability, to tune up every single piece of the chatbot
16-
- REST API: the MiniPilot can serve remote users over a REST API. The UI is for demonstrative purposes.
16+
- REST API: the Minipilot can serve remote users over a REST API. The UI is for demonstrative purposes.
1717
- Centralized Redis session, so application servers are purely stateless, which helps scalability of the service
1818

19-
## What can I do with MiniPilot?
19+
## What can I do with Minipilot?
2020

2121
You can use the code for self-learning, extend it as desired and use in production. The source code sheds light on all the standard components used in these kinds of systems:
2222

docs/installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Then, decide where you want to run your Redis Stack instance.
1515

1616
## Local setup
1717

18-
To run MiniPilot on your laptop, just clone the repository.
18+
To run Minipilot on your laptop, just clone the repository.
1919

2020
```commandline
2121
git clone https://github.com/redis/MiniPilot.git
@@ -81,10 +81,10 @@ DB_PORT The port of your Redis Stack instance or Redis Cloud data
8181
DB_PWD The password of your Redis Stack instance or Redis Cloud database
8282
DB_SSL If you would like to connect using SSL (mandatory for Redis Cloud databases)
8383
OPENAI_API_KEY Your OpenAI token
84-
MINIPILOT_ENDPOINT MiniPilot is a REST API service, but the internal chat interface uses the REST API, too, on the default exposed port 8000. You can just leave http://127.0.0.1:8000
84+
MINIPILOT_ENDPOINT Minipilot is a REST API service, but the internal chat interface uses the REST API, too, on the default exposed port 8000. You can just leave http://127.0.0.1:8000
8585
```
8686

87-
## Configuring MiniPilot
87+
## Configuring Minipilot
8888

8989
1. point your browser to [http://127.0.0.1:5005/](http://127.0.0.1:5005/)
9090
2. From the `data` tab, load a CSV dataset, and index it. You can try the [IMDB movies dataset](https://www.kaggle.com/datasets/ashpalsingh1525/imdb-movies-dataset)

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Usage
22

3-
MiniPilot is a highly configurable server. Read the environment variables to customize the server's behavior.
3+
Minipilot is a highly configurable server. Read the environment variables to customize the server's behavior.
44

55
| Variable | Description | Default |
66
|----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|-------------------|

src/core/RedisRetrievalChain.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,14 @@ def __ask_question(self, q, callback_fn: StreamingStdOutCallbackHandlerYield):
9292
callback_fn.q.put(cached[0]['response'])
9393
callback_fn.q.put(STOP_ITEM)
9494

95-
# The question is in the cache, but I want to save the conversation in the history too
95+
# The question is in the cache, but we want to save the conversation in the history too
9696
metadata = {}
9797
if 'metadata' in cached[0]:
9898
metadata = cached[0]['metadata']
9999
redis_history.add_user_message(q)
100100
redis_history.add_message(BaseMessage(content=cached[0]['response'], type="ai", additional_kwargs=metadata))
101101
return
102102

103-
# Note that a try/catch is not needed here. Callback takes care of all errors in `on_llm_error`
104103
# llm = OpenAI(streaming=True, callbacks=[callback_fn])
105104
streaming_llm = ChatOpenAI(
106105
model_name=self.model,
@@ -138,14 +137,14 @@ def get_chat_history(inputs) -> str:
138137
# now you can rebuild this using https://js.langchain.com/v0.1/docs/use_cases/code_understanding/#chat
139138
# https://python.langchain.com/v0.2/docs/versions/migrating_chains/conversation_retrieval_chain/
140139
chatbot = ConversationalRetrievalChain.from_llm(llm=streaming_llm,
141-
retriever=self.__get_retriever_with_score(MINIPILOT_CONTEXT_LENGTH),
142-
get_chat_history=get_chat_history,
140+
retriever=self.__get_retriever_with_score(MINIPILOT_CONTEXT_LENGTH), # RAG
141+
get_chat_history=get_chat_history, # LLM Memory
143142
rephrase_question=False,
144143
return_generated_question=True,
145144
verbose=MINIPILOT_DEBUG,
146145
return_source_documents=True,
147-
condense_question_llm = ChatOpenAI(temperature=0, model=self.model),
148-
combine_docs_chain_kwargs={'prompt': qa_prompt})
146+
condense_question_llm = ChatOpenAI(temperature=0, model=self.model), # LLM Memory part 2: condense
147+
combine_docs_chain_kwargs={'prompt': qa_prompt}) # Agentic Memory
149148

150149
result = None
151150
try:
@@ -162,9 +161,8 @@ def get_chat_history(inputs) -> str:
162161

163162
"""
164163
Update the cache only if caching is enabled AND there was context retrieved for RAG
165-
in such a case, we may save the generated standalone question, which also includes summarization of the history
166-
but for now we save the original question, or a user repeating over and over a question, will never see his own cached question.
167-
Having references means that there is semantic content available in the database, so the question should make sense
164+
First, we save the generated standalone question, which also includes summarization of the history
165+
Second, having references means that there is semantic content available in the database, so the question should make sense
168166
and it can be stored, otherwise the following might happen:
169167
1. ask a question "can this or that happen?"
170168
2. get references for RAG, forward the prompt to the LMM and get an answer, hence cache the pair question/asnwer

src/static/.DS_Store

0 Bytes
Binary file not shown.

src/templates/botbar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<form class="search-form mt-4 p-2 pl-4" method="post" action="">
22
<div class="field has-addons">
33
<div class="control is-expanded is-flex is-vcentered">
4-
<input name="q" autocomplete="off" class="search-bar" type="text" placeholder="Ask the MiniPilot a question...">
4+
<input name="q" autocomplete="off" class="search-bar" type="text" placeholder="Ask Minipilot a question...">
55
</div>
66
<div class="control has-icons-left">
77
<button id="chat" disabled type="submit" class="button search-button" autocomplete="off">

src/templates/chat.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="column is-two-thirds is-full-mobile">
99
<div class="bubble bubble-initial text-lg tracking-tight">
1010
<p>
11-
Hello! I am the MiniPilot, how can I help you?
11+
Hello! I am the Minipilot, how can I help you?
1212
</p>
1313
</div>
1414
<span id="conversation">

0 commit comments

Comments
 (0)