API to interact with the Mistral "LARGE" model of Spring, using their API via Spring and adding context if necessary via document search.
To use the Mistral API, you must register on the Mistral website and obtain an API key.
Then, you must enter it in the spring.ai.mistralai.api-key property in one of the configuration files.
The project is based on ChromaDB, a vector database. To install the Chroma client, simply follow these instructions:
pip install chromadbThen, you need to launch a new instance of ChromaDB:
chroma run --host localhost --port 8000 --path ./my_chroma_dataTo use the Tavily web search API, you need to register on the Tavily website and obtain an API key.
Then, you need to enter it in the tavily.api-key property in one of the configuration files.
Depending of route used, LLM will get previous context from conversation with an "in-memory" database (If you restart API, memory is cleared).
It can use a RAG for search into ChromaDB to get more context, or search on the web with Tavily. If required, the API has a little "reasoning" feature for LLM which is composed of 2 steps : make a detailed plan, and explain it precisely.
The API allows you to import documents into the ChromaDB database. During import, document follow these steps:
- Split into chunks
- Enrich metadata with summary of previous, current and next chunk to make better retrieval in the future
- Extract main keywords of document
When API is used to search document, it will search into ChromaDB database. It will return the most relevant documents according to the search query. Documents with a retrieval score of > 0.8 are fully returned to the final prompt, and the others are all joined to be summarized to not send irrelevant informations.
Ask a question though the /api/v1/streaming-chat route, and a workflow will be created automatically to anwser your question, based on the agents declared with the SmartAgentFlowFactory bean.
The API has a GET route /api/v1/streaming-chat that allows you to communicate with the Mistral "LARGE" model. It is possible to search by document or a web search by entering the associated booleans in the body of the request.
Before you can use the document search, you need to add documents to the ChromaDB database. To do this, simply make a POST request to /api/v1/documents with the desired file.