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
- 🔥🔥[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.
- 🔥🔥[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.
31
49
-[2023.08.26] codefuse-ModelCache...
50
+
32
51
### Introduction
52
+
33
53
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.
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
+
38
66
### Dependencies
39
67
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
55
103
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
66
104
The current service provides three core functionalities through RESTful API.: Cache-Writing, Cache-Querying, and Cache-Clearing. Demos:
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.
112
154
113
155
<table>
114
156
<tr>
@@ -231,45 +273,59 @@ In terms of functionality, we have made several changes to the git repository. F
231
273
</tr>
232
274
</table>
233
275
234
-
235
276
## Core-Features
277
+
236
278
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:
237
279
238
280
-[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.
245
287
-[x] Support for System Commands: Adopting a concatenation approach to address the issue of system commands in the prompt format.
246
288
-[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.
247
289
-[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.
253
295
254
296
## Todo List
297
+
255
298
### Adapter
299
+
256
300
-[ ] Register adapter for Milvus:Based on the "model" parameter in the scope, initialize the corresponding Collection and perform the load operation.
301
+
257
302
### Embedding model&inference
303
+
258
304
-[ ] Inference Optimization: Optimizing the speed of embedding inference, compatible with inference engines such as FasterTransformer, TurboTransformers, and ByteTransformer.
259
305
-[ ] Compatibility with Hugging Face models and ModelScope models, offering more methods for model loading.
306
+
260
307
### Scalar Storage
308
+
261
309
-[ ] Support MongoDB
262
310
-[ ] Support ElasticSearch
311
+
263
312
### Vector Storage
313
+
264
314
-[ ] Adapts Faiss storage in multimodal scenarios.
315
+
265
316
### Ranking
317
+
266
318
-[ ] Add ranking model to refine the order of data after embedding recall.
319
+
267
320
### Service
321
+
268
322
-[ ] Supports FastAPI.
269
323
-[ ] Add visual interface to offer a more direct user experience.
270
324
271
325
## Acknowledgements
326
+
272
327
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)
273
328
274
329
## 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