Add new indexing and reasoning pipeline to the application¶
@trducng
At high level, to add new indexing and reasoning pipeline:
- You define your indexing or reasoning pipeline as a class from
BaseComponent
. - You declare that class in the setting files
flowsettings.py
.
Then when python app.py
, the application will dynamically load those
pipelines.
The below sections talk in more detail about how the pipelines should be constructed.
Define a pipeline as a class¶
In essence, a pipeline will subclass from kotaemon.base.BaseComponent
.
Each pipeline has 2 main parts:
- All declared arguments and sub-pipelines.
- The logic inside the pipeline.
An example pipeline:
This pipeline is simple for demonstration purpose, but we can imagine pipelines
with much more arguments, that can take other pipelines as arguments, and have
more complicated logic in the run
method.
An indexing or reasoning pipeline is just a class subclass from
BaseComponent
like above.
For more detail on this topic, please refer to Creating a Component
Run signatures¶
Note: this section is tentative at the moment. We will finalize def run
function signature by latest early April.
The indexing pipeline:
The reasoning pipeline:
Register your pipeline to ktem¶
To register your pipelines to ktem, you declare it in the flowsettings.py
file. This file locates at the current working directory where you start the
ktem. In most use cases, it is this
one.
You can register multiple reasoning pipelines to ktem by populating the
KH_REASONING
list. The user can select which reasoning pipeline to use
in their Settings page.
For now, there's only one supported index option for KH_INDEX
.
Make sure that your class is discoverable by Python.
Allow users to customize your pipeline in the app settings¶
To allow the users to configure your pipeline, you need to declare what you
allow the users to configure as a dictionary. ktem
will include them into the
application settings.
In your pipeline class, add a classmethod get_user_settings
that returns a
setting dictionary, add a classmethod get_info
that returns an info
dictionary. Example:
Once adding these methods to your pipeline class, ktem
will automatically
extract and add them to the settings.
Construct to pipeline object¶
Once ktem
runs your pipeline, it will call your classmethod get_pipeline
with the full user settings and expect to obtain the pipeline object. Within
this get_pipeline
method, you implement all the necessary logics to initiate
the pipeline object. Example:
Reasoning: Stream output to UI¶
For fast user experience, you can stream the output directly to UI. This way, user can start observing the output as soon as the LLM model generates the 1st token, rather than having to wait the pipeline finishes to read the whole message.
To stream the output, you need to;
- Turn the
run
function to async. - Pass in the output to a special queue with
self.report_output
.
The argument to self.report_output
is a dictionary, that contains either or
all of these 2 keys: "output", "evidence". The "output" string will be streamed
to the chat message, and the "evidence" string will be streamed to the
information panel.
Access application LLMs, Embeddings¶
You can access users' collections of LLMs and embedding models with:
You can also allow the users to specifically select which llms or embedding models they want to use through the settings.
Optional: Access application data¶
You can access the user's application database, vector store as follow: