Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Adding Redis caching layer #35

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

chiruu12
Copy link

Description

This pull request introduces some improvements to b0bot

  • Redis Integration:
    A Redis caching layer has been added to cache requests, which should help improve performance by reducing redundant calls.
  • Testing & Documentation:
    Tests for the new Redis functionality have been added. The README.md and other documentation files have been updated to reflect these changes.
  • Minor Code Updates:
    Additional small refactors were made to improve code consistency.
  • LLM Configuration Update:
    The initialization of HuggingFaceEndpoint was updated by replacing the previous repo_id and token parameters with model=self.model_name

Related Issue:
This PR is for recently added issue #33 - Implement Redis Caching for Faster News Retrieval.

Motivation and Context:
The main motivation for this change is to cache external requests using Redis. This enhancement should reduce latency and lower the load on our external services. The LLM configuration update also aligns with our current project standards and simplifies maintenance.

How Has This Been Tested?:

  • The Redis caching functionality and updated LLM configuration have been verified using our Docker-based testing environment.
  • Tests were added for testing redis connection Also using docker(for windows) .
  • Manual tests were performed to confirm that the application behavior is as expected with these new changes.

Logs with comments

  • Client requests the homepage. No LLM processing is needed.
    127.0.0.1 - - [26/Feb/2025 07:48:56] "GET / HTTP/1.1" 200 -

  • Client requests the favicon.
    127.0.0.1 - - [26/Feb/2025 07:48:57] "GET /favicon.ico HTTP/1.1" 204 -

  • Client makes a request for "red hat ".
    Since this is the first time this detailed query is received, no cached response exists.
    The system triggers the LLM to fetch and process the request, and the resulting response is cached.
    127.0.0.1 - - [26/Feb/2025 07:48:59] "GET /mistralai/news_keywords?keywords=red+hat HTTP/1.1" 200 -

  • Client makes another request, this time again for "red hat".
    The system recognizes the cached response to the previous query and retrieves the response from cache,
    thereby avoiding a redundant LLM call.
    127.0.0.1 - - [26/Feb/2025 07:50:07] "GET /mistralai/news_keywords?keywords=red+hat HTTP/1.1" 200 -

Screenshots (if appropriate):
Below are the screenshot taken during a testing in which we can see the responses for the cached
Screenshot 2025-02-26 080452
Screenshot 2025-02-26 080507
Screenshot 2025-02-26 080519

Future Improvement Note:

In future, we can implement an agentic caching mechanism.
This new mechanism will analyze incoming requests (e.g., "red hat hackers latest news" vs. "red hat")
to determine if existing cached responses can be reused for similar contexts,
thereby making external LLM calls only when necessary.

Types of changes:

  • Bug fix
  • New feature (updated HuggingFaceEndpoint usage, Redis caching integration, and tests)
  • Breaking change (none)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly (README.md updated).
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.(partially)
  • All new and existing tests passed.

@hardik1408
Copy link
Contributor

Can you test how much of a time difference this is making while fetching the responses?

@chiruu12
Copy link
Author

Sure! I'll run some benchmarks to compare the response times with and without Redis caching. I'll update the PR with the detailed stats (and screenshots if needed) in a follow-up commit.

@chiruu12
Copy link
Author

I did a few tests and the results were consistent throughout these are the last 2 tests I performed
Test 1:
Before cache: 21.278 seconds
After cache: 5 ms
Screenshot 2025-02-26 113616

Test 2:
Before cache: 22.4 seconds
After cache: 4.99 ms
Screenshot 2025-02-26 113552

@chiruu12
Copy link
Author

@hardik1408 I’ve also added Docker files to the repository. This enhancement will make it much easier for everyone to deploy and run the app in a consistent, containerized environment. The updated README now includes detailed instructions on how to build and run the Docker container (or use Docker Compose)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants