Skip to content

Commit 2556eb6

Browse files
committed
add docs
1 parent d29299d commit 2556eb6

File tree

7 files changed

+169
-68
lines changed

7 files changed

+169
-68
lines changed

README.md

Lines changed: 121 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,102 @@ ModelCache
99
<h4 align="center">
1010
<p>
1111
<a href="https://github.com/codefuse-ai/CodeFuse-ModelCache/blob/main/README_CN.md">中文</a> |
12-
<b>English</b>
12+
<b>English</b>
1313
</p>
1414
</h4>
1515
</div>
1616

1717
## Contents
18-
- [news](#news)
19-
- [Introduction](#Introduction)
20-
- [Quick-Deployment](#Quick-Deployment)
21-
- [Service-Access](#Service-Access)
22-
- [Articles](#Articles)
23-
- [Modules](#Modules)
24-
- [Core-Features](#Core-Features)
25-
- [Acknowledgements](#Acknowledgements)
26-
- [Contributing](#Contributing)
27-
## news
28-
- 🔥🔥[2024.04.09] Add Redis Search to store and retrieve embeddings in multi-tenant scene, this can reduce the interaction time between Cache and vector databases to 10ms.
29-
- 🔥🔥[2023.12.10] we integrate LLM embedding frameworks such as 'llmEmb', 'ONNX', 'PaddleNLP', 'FastText', alone with the image embedding framework 'timm', to bolster embedding functionality.
30-
- 🔥🔥[2023.11.20] codefuse-ModelCache has integrated local storage, such as sqlite and faiss, providing users with the convenience of quickly initiating tests.
18+
19+
- [Contents](#contents)
20+
- [News](#news)
21+
- [Introduction](#introduction)
22+
- [Architecture](#architecture)
23+
- [Quick start](#quick-start)
24+
- [Dependencies](#dependencies)
25+
- [Start service](#start-service)
26+
- [Start Demo](#start-demo)
27+
- [Start normal service](#start-normal-service)
28+
- [Access the service](#access-the-service)
29+
- [Write cache](#write-cache)
30+
- [Query cache](#query-cache)
31+
- [Clear cache](#clear-cache)
32+
- [Function comparison](#function-comparison)
33+
- [Core-Features](#core-features)
34+
- [Todo List](#todo-list)
35+
- [Adapter](#adapter)
36+
- [Embedding model\&inference](#embedding-modelinference)
37+
- [Scalar Storage](#scalar-storage)
38+
- [Vector Storage](#vector-storage)
39+
- [Ranking](#ranking)
40+
- [Service](#service)
41+
- [Acknowledgements](#acknowledgements)
42+
- [Contributing](#contributing)
43+
44+
## News
45+
46+
- 🔥🔥[2024.04.09] Added Redis Search to store and retrieve embeddings in multi-tenant. This can reduce the interaction time between Cache and vector databases to 10ms.
47+
- 🔥🔥[2023.12.10] Integrated LLM embedding frameworks such as 'llmEmb', 'ONNX', 'PaddleNLP', 'FastText', and the image embedding framework 'timm' to bolster embedding functionality.
48+
- 🔥🔥[2023.11.20] Integrated local storage, such as sqlite and faiss. This enables you to initiate quick and convenient tests.
3149
- [2023.08.26] codefuse-ModelCache...
50+
3251
### Introduction
52+
3353
Codefuse-ModelCache is a semantic cache for large language models (LLMs). By caching pre-generated model results, it reduces response time for similar requests and improves user experience. <br />This project aims to optimize services by introducing a caching mechanism. It helps businesses and research institutions reduce the cost of inference deployment, improve model performance and efficiency, and provide scalable services for large models. Through open-source, we aim to share and exchange technologies related to large model semantic cache.
34-
## Quick Deployment
35-
The project's startup scripts are divided into flask4modelcache.py and flask4modelcache_demo.py.
36-
- flask4modelcache_demo.py is a quick test service that embeds sqlite and faiss, and users do not need to be concerned about database-related matters.
37-
- flask4modelcache.py is the normal service that requires configuration of mysql and milvus database services.
54+
55+
## Architecture
56+
57+
![modelcache modules](docs/modelcache_modules_20240409.png)
58+
59+
## Quick start
60+
61+
You can find the start script in `flask4modelcache.py` and `flask4modelcache_demo.py`.
62+
63+
- `flask4modelcache_demo.py` is a quick test service that embeds sqlite and faiss. You do not need to be concerned about database-related matters.
64+
- `flask4modelcache.py` is the normal service that requires configuration of MySQL and Milvus.
65+
3866
### Dependencies
3967

40-
- Python version: 3.8 and above
41-
- Package Installation
42-
```shell
43-
pip install -r requirements.txt
44-
```
45-
### Service Startup
46-
#### Demo Service Startup
47-
1. Download the embedding model bin file from the following address: [https://huggingface.co/shibing624/text2vec-base-chinese/tree/main](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main). Place the downloaded bin file in the model/text2vec-base-chinese folder.
48-
2. Start the backend service using the flask4modelcache_dome.py script.
49-
```shell
50-
cd CodeFuse-ModelCache
51-
```
52-
```shell
53-
python flask4modelcache_demo.py
54-
```
68+
- Python: V3.8 and above
69+
- Package installation
70+
71+
```shell
72+
pip install -r requirements.txt
73+
```
74+
75+
### Start service
76+
77+
#### Start Demo
78+
79+
1. Download the embedding model bin file on [Hugging Face](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main). Place the downloaded bin file in the model/text2vec-base-chinese folder.
80+
2. Start the backend service by using `flask4modelcache_dome.py`.
81+
82+
```shell
83+
cd CodeFuse-ModelCache
84+
```
85+
86+
```shell
87+
python flask4modelcache_demo.py
88+
```
89+
90+
#### Start normal service
91+
92+
Before you start normal service, make sure that you have completed these steps:
93+
94+
1. Install the relational database MySQL and import the SQL file to create the data tables. You can find the SQL file in `reference_doc/create_table.sql`.
95+
2. Install vector database Milvus.
96+
3. Add the database access information to the configuration files:
97+
1. `modelcache/config/milvus_config.ini`
98+
2. `modelcache/config/mysql_config.ini`
99+
4. Download the embedding model bin file from [Hugging Face](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main). Put the bin file in the `model/text2vec-base-chinese` directory.
100+
5. Start the backend service by using the `flask4modelcache.py` script.
101+
102+
## Access the service
55103

56-
#### Normal Service Startup
57-
Before starting the service, the following environment configurations should be performed:
58-
1. Install the relational database MySQL and import the SQL file to create the data tables. The SQL file can be found at: ```reference_doc/create_table.sql```
59-
2. Install the vector database Milvus.
60-
3. Add the database access information to the configuration files:
61-
1. ```modelcache/config/milvus_config.ini ```
62-
2. ```modelcache/config/mysql_config.ini```
63-
4. Download the embedding model bin file from the following address: [https://huggingface.co/shibing624/text2vec-base-chinese/tree/main](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main). Place the downloaded bin file in the model/text2vec-base-chinese folder.
64-
5. Start the backend service using the flask4modelcache.py script.
65-
## Service-Access
66104
The current service provides three core functionalities through RESTful API.: Cache-Writing, Cache-Querying, and Cache-Clearing. Demos:
67-
### Cache-Writing
105+
106+
### Write cache
107+
68108
```python
69109
import json
70110
import requests
@@ -77,7 +117,9 @@ data = {'type': type, 'scope': scope, 'chat_info': chat_info}
77117
headers = {"Content-Type": "application/json"}
78118
res = requests.post(url, headers=headers, json=json.dumps(data))
79119
```
80-
### Cache-Querying
120+
121+
### Query cache
122+
81123
```python
82124
import json
83125
import requests
@@ -90,7 +132,9 @@ data = {'type': type, 'scope': scope, 'query': query}
90132
headers = {"Content-Type": "application/json"}
91133
res = requests.post(url, headers=headers, json=json.dumps(data))
92134
```
93-
### Cache-Clearing
135+
136+
### Clear cache
137+
94138
```python
95139
import json
96140
import requests
@@ -103,12 +147,10 @@ data = {'type': type, 'scope': scope, 'remove_type': remove_type}
103147
headers = {"Content-Type": "application/json"}
104148
res = requests.post(url, headers=headers, json=json.dumps(data))
105149
```
106-
## Articles
107-
https://mp.weixin.qq.com/s/ExIRu2o7yvXa6nNLZcCfhQ
108-
## modules
109-
![modelcache modules](docs/modelcache_modules_20240409.png)
110-
## Function-Comparison
111-
In terms of functionality, we have made several changes to the git repository. Firstly, we have addressed the network issues with huggingface and enhanced the inference speed by introducing local inference capabilities for embeddings. Additionally, considering the limitations of the SqlAlchemy framework, we have completely revamped the module responsible for interacting with relational databases, enabling more flexible database operations. In practical scenarios, LLM products often require integration with multiple users and multiple models. Hence, we have added support for multi-tenancy in the ModelCache, while also making preliminary compatibility adjustments for system commands and multi-turn dialogue.
150+
151+
## Function comparison
152+
153+
We've implemented several key updates to our repository. We've resolved network issues with Hugging Face and improved inference speed by introducing local embedding capabilities. Due to limitations in SqlAlchemy, we've redesigned our relational database interaction module for more flexible operations. We've added multi-tenancy support to ModelCache, recognizing the need for multiple users and models in LLM products. Lastly, we've made initial adjustments for better compatibility with system commands and multi-turn dialogues.
112154

113155
<table>
114156
<tr>
@@ -231,45 +273,59 @@ In terms of functionality, we have made several changes to the git repository. F
231273
</tr>
232274
</table>
233275

234-
235276
## Core-Features
277+
236278
In ModelCache, we adopted the main idea of GPTCache, includes core modules: adapter, embedding, similarity, and data_manager. The adapter module is responsible for handling the business logic of various tasks and can connect the embedding, similarity, and data_manager modules. The embedding module is mainly responsible for converting text into semantic vector representations, it transforms user queries into vector form.The rank module is used for sorting and evaluating the similarity of the recalled vectors. The data_manager module is primarily used for managing the database. In order to better facilitate industrial applications, we have made architectural and functional upgrades as follows:
237279

238280
- [x] We have modified it similar to Redis and embedded it into the LLMs product, providing semantic caching capabilities. This ensures that it does not interfere with LLM calls, security audits, and other functionalities, achieving compatibility with all large-scale model services.
239-
- [x] Multiple Model Loading Schemes:
240-
- Support loading local embedding models to address Hugging Face network connectivity issues.
241-
- Support loading various pretrained model embedding layers.
242-
- [x] Data Isolation Capability
243-
- Environment Isolation: Can pull different database configurations based on the environment to achieve environment isolation (dev, prepub, prod).
244-
- Multi-tenant Data Isolation: Dynamically create collections based on the model for data isolation, addressing data isolation issues in multi-model/services scenarios in LLMs products.
281+
- [x] Multiple Model Loading Schemes:
282+
- Support loading local embedding models to address Hugging Face network connectivity issues.
283+
- Support loading various pretrained model embedding layers.
284+
- [x] Data Isolation Capability
285+
- Environment Isolation: Can pull different database configurations based on the environment to achieve environment isolation (dev, prepub, prod).
286+
- Multi-tenant Data Isolation: Dynamically create collections based on the model for data isolation, addressing data isolation issues in multi-model/services scenarios in LLMs products.
245287
- [x] Support for System Commands: Adopting a concatenation approach to address the issue of system commands in the prompt format.
246288
- [x] Differentiation of Long and Short Texts: Long texts pose more challenges for similarity evaluation. To address this, we have added differentiation between long and short texts, allowing for separate configuration of threshold values for determining similarity.
247289
- [x] Milvus Performance Optimization: The consistency_level of Milvus has been adjusted to "Session" level, which can result in better performance.
248-
- [x] Data Management Capability:
249-
- Ability to clear the cache, used for data management after model upgrades.
250-
- Hitquery recall for subsequent data analysis and model iteration reference.
251-
- Asynchronous log write-back capability for data analysis and statistics.
252-
- Added model field and data statistics field for feature expansion.
290+
- [x] Data Management Capability:
291+
- Ability to clear the cache, used for data management after model upgrades.
292+
- Hitquery recall for subsequent data analysis and model iteration reference.
293+
- Asynchronous log write-back capability for data analysis and statistics.
294+
- Added model field and data statistics field for feature expansion.
253295

254296
## Todo List
297+
255298
### Adapter
299+
256300
- [ ] Register adapter for Milvus:Based on the "model" parameter in the scope, initialize the corresponding Collection and perform the load operation.
301+
257302
### Embedding model&inference
303+
258304
- [ ] Inference Optimization: Optimizing the speed of embedding inference, compatible with inference engines such as FasterTransformer, TurboTransformers, and ByteTransformer.
259305
- [ ] Compatibility with Hugging Face models and ModelScope models, offering more methods for model loading.
306+
260307
### Scalar Storage
308+
261309
- [ ] Support MongoDB
262310
- [ ] Support ElasticSearch
311+
263312
### Vector Storage
313+
264314
- [ ] Adapts Faiss storage in multimodal scenarios.
315+
265316
### Ranking
317+
266318
- [ ] Add ranking model to refine the order of data after embedding recall.
319+
267320
### Service
321+
268322
- [ ] Supports FastAPI.
269323
- [ ] Add visual interface to offer a more direct user experience.
270324

271325
## Acknowledgements
326+
272327
This project has referenced the following open-source projects. We would like to express our gratitude to the projects and their developers for their contributions and research.<br />[GPTCache](https://github.com/zilliztech/GPTCache)
273328

274329
## Contributing
275-
ModelCache is a captivating and invaluable project, whether you are an experienced developer or a novice just starting out, your contributions to this project are warmly welcomed. Your involvement in this project, be it through raising issues, providing suggestions, writing code, or documenting and creating examples, will enhance the project's quality and make a significant contribution to the open-source community.
330+
331+
ModelCache is a captivating and invaluable project, whether you are an experienced developer or a novice just starting out, your contributions to this project are warmly welcomed. Your involvement in this project, be it through raising issues, providing suggestions, writing code, or documenting and creating examples, will enhance the project's quality and make a significant contribution to the open-source community.

0 commit comments

Comments
 (0)