GPTCache란 무엇인가요?
GPTCache는 언어 모델이 생성한 응답을 저장하는 캐시를 구현하여 GPT 기반 애플리케이션의 효율성과 속도를 개선하도록 설계된 오픈소스 라이브러리입니다. GPTCache는 사용자가 필요에 맞게 캐시를 사용자화할 수 있는 옵션을 제공하며, 임베딩 함수, 유사성 평가 함수, 저장 위치 및 제거 기능을 포함합니다. 또한 GPTCache는 현재 OpenAI ChatGPT 인터페이스와 Langchain 인터페이스를 지원합니다.

강력하고 성장하는 커뮤니티 기반.
7,976+
GitHub 스타
왜 GPTCache를 사용해야 하나요?
성능 향상
LLM 응답을 캐시에서 저장하면, 이전에 요청된 응답이 이미 캐시되어 있을 때 응답을 검색하는 시간이 크게 단축될 수 있습니다. 캐시에서 응답을 저장하면 애플리케이션의 전체 성능이 향상됩니다.
비용 절감
대부분의 LLM 서비스는 요청 수와 토큰 수에 따라 요금을 부과합니다. LLM 응답을 캐시하면 서비스에 대한 API 호출 횟수를 줄여 비용 절감 효과를 얻을 수 있습니다. 특히 높은 트래픽에서 API 호출 비용이 상당할 수 있습니다.
확장성 개선
LLM 응답을 캐시하면 애플리케이션의 확장성이 향상됩니다. 캐시는 LLM 서비스의 부하를 줄이고 병목 현상을 피하며 애플리케이션이 증가하는 요청 수를 처리할 수 있도록 도와줍니다.
개발 비용 절감
의미 기반 캐시는 LLM(언어 모델) 앱 개발 중 비용을 절감하는 데 유용한 도구가 될 수 있습니다. LLM 애플리케이션은 개발 중에도 LLM API 연결이 필요하며, 이는 비용이 많이 들 수 있습니다. GPTCache는 LLM API와 동일한 인터페이스를 제공하고 LLM 생성 또는 가상 데이터를 저장할 수 있습니다. GPTCache는 LLM API나 네트워크와 연결하지 않고도 애플리케이션의 기능을 검증할 수 있도록 도와줍니다.
네트워크 지연 감소
사용자의 기기 근처에 위치한 의미 기반 캐시는 LLM 서비스에서 데이터를 검색하는 시간을 줄여줍니다. 네트워크 지연을 줄이면 전체 사용자 경험이 향상됩니다.
가용성 향상
LLM 서비스는 자주 사용 제한을 두며, 이는 사용자가 주어진 시간 내에 서버에 접근할 수 있는 횟수를 제한하는 API 제약입니다. 제한을 초과하면 추가 요청이 차단되어 서비스 중단이 발생할 수 있습니다. GPTCache는 증가하는 쿼리 볼륨을 수용할 수 있도록 빠르게 확장할 수 있어 애플리케이션의 사용자 기반이 확대되더라도 일관된 성능을 보장합니다.
전체적으로, LLM 응답을 저장하기 위한 의미 기반 캐시를 개발하는 것은 성능 향상, 비용 절감, 확장성 개선, 사용자화 및 네트워크 지연 감소와 같은 다양한 이점을 제공합니다.
GPTCache의 작동 원리
GPTCache는 온라인 서비스에서 데이터 지역성을 활용하여 자주 액세스되는 데이터를 저장하고 검색 시간을 단축하며 백엔드 서버 부하를 완화합니다. 전통적인 캐시 시스템과 달리 GPTCache는 의미 기반 캐싱을 사용하여 유사하거나 관련된 쿼리를 식별하고 저장하여 캐시 적중률을 향상시킵니다.
임베딩 알고리즘을 사용하여 GPTCache는 쿼리를 임베딩으로 변환하고 벡터 스토어를 사용하여 유사성 검색을 수행하여 캐시에서 관련된 쿼리를 검색할 수 있습니다. GPTCache의 모듈화된 설계는 각 모듈에 대해 다양한 구현을 사용자가 사용자화할 수 있게 해줍니다.
의미 기반 캐싱은 거짓 긍정과 거짓 부정이 발생할 수 있지만, GPTCache는 개발자가 캐싱 시스템을 최적화할 수 있도록 돕기 위해 세 가지 성능 지표를 제공합니다.
이 과정은 GPTCache가 캐시 저장소에서 유사하거나 관련된 쿼리를 식별하고 검색할 수 있도록 합니다. 아래 다이어그램에서 이 과정을 확인할 수 있습니다.
Customize semantic cache
GPTCache was built with a modular design to make it easy for users to customize their semantic cache. Each module has options for the users to choose from to fit their needs.
Pre-processor Pre-processor manages, analyzes, and formats the queries sent to LLMs, including removing redundant information from inputs, compressing input information, cutting long texts, and performing other related tasks.
LLM Adapter The LLM Adapter integrates with different LLM models and is standardized on the OpenAI API, unifying their APIs and request protocols. The LLM Adapter allows for easier experimentation and testing with various LLM models, as you can switch between them without having to rewrite your code or learn a new API. Support is available for:
- OpenAI ChatGPT API
- langchain
- Minigpt4
- Llamacpp
- Roadmap — Hugging Face Hub, Bard and Anthropic
Embedding Generator The Embedding Generator generates embeddings with the model of your choice from the request queue to execute a similarity search. Models that are supported include OpenAI embedding API. ONNX with the GPTCache/paraphrase-albert-onnx model, Hugging Face embedding API, Cohere embedding API, fastText embedding API, and the SentenceTransformers embedding API and Timm models for image embeddings.
Cache Store Cache Store is where the response from LLMs, such as ChatGPT, is stored. Cached responses are retrieved to assist in evaluating similarity and are returned to the requester if there is a good semantic match. GPTCache supports SQLite, PostgreSQL, MySQL, MariaDB, SQL Server, and Oracle. Supporting popular databases means that users can choose the database that best fits their needs, depending on performance, scalability, and cost.
Vector Store options GPTCache supports a Vector Store module, which helps to find the K most similar requests based on the extracted embeddings from the input request. This functionality can help assess the similarity between requests. In addition, GPTCache provides a user-friendly interface that supports various vector stores, including Milvus, Zilliz Cloud, Milvus Lite, Hnswlib, PGVector, Chroma, DocArray and FAISS. These options give users a range of choices for vector stores, which can affect the efficiency and accuracy of the similarity search functionality in GPTCache. GPTCache aims to provide flexibility and cater to a broader range of use cases by supporting multiple vector stores.
Eviction Policy Management Cache Manager in GPTCache controls the operations of both the Cache Store and Vector Store modules. When the cache becomes full, a replacement policy determines which data to evict to make room for new data. GPTCache currently supports two basic options: - LRU (Least Recently Used) eviction policy - FIFO (First In, First Out) eviction policy These are both standard eviction policies used in caching systems.
Similarity Evaluator The Similarity Evaluator module in GPTCache collects data from Cache Storage and Vector Store. It uses various strategies to determine the similarity between the input request and the requests from the Vector Store. The similarity determines whether a request matches the cache. GPTCache provides a standardized interface for integrating various similarity strategies and a collection of implementations. These different similarity strategies allow GPTCache to provide flexibility in determining cache matches based on other use cases and needs.
Post-Processor Post-processor prepares the final response to return to the user when the cache is hit. If the answer is not in the cache, the LLM Adapter requests responses from LLM and writes them back to the Cache Manager.
