Skip to content

Commit 70e08d8

Browse files
Merge pull request #634 from wjohnsto/master
Adjusting video QA tutorial URL and adding images and data snippets
2 parents 2db0a31 + 1a3dbdb commit 70e08d8

File tree

9 files changed

+101
-14
lines changed

9 files changed

+101
-14
lines changed

docs/howtos/solutions/index-solutions.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ Learn how to easily build, test and deploy code for common microservice and cach
192192
/>
193193
</div>
194194

195+
<div class="col">
196+
<RedisCard
197+
title="AI Video Q&A with Redis and Langchain"
198+
description="Building an AI-Powered Video Q&A Application with Redis and LangChain (OpenAI and Gemini)"
199+
page="/howtos/solutions/vector/ai-qa-videos-langchain-redis-openai-google"
200+
/>
201+
</div>
202+
195203
</div>
196204

197205
## Triggers and Functions

docs/howtos/solutions/triggers-and-functions/getting-started-tf/index-triggers-and-functions.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,6 @@ redis.registerStreamTrigger(
444444
'calculateStats', // trigger name
445445
'TRANSACTION_STREAM', // Detects new data added to the stream
446446
function (client, data) {
447-
// data = JSON.stringify(
448-
// data,
449-
// (key, value) => (typeof value === "bigint" ? value.toString() : value) //id conversion
450-
// );
451-
452-
// data = JSON.parse(data);
453-
454447
var streamEntry = {};
455448
for (let i = 0; i < data.record?.length; i++) {
456449
streamEntry[data.record[i][0]] = data.record[i][1];
@@ -528,6 +521,13 @@ redis.registerStreamTrigger(
528521
);
529522
```
530523
524+
In above `calculateStats` function, we are listening to `TRANSACTION_STREAM` and updating different sales statistics like
525+
526+
- `statsTotalPurchaseAmount` variable stores total purchase amount
527+
- `statsProductPurchaseQtySet` is a sorted set which tracks trending products based on highest purchase quantity
528+
- `statsCategoryPurchaseAmountSet` is a sorted set which tracks category wise purchase interest
529+
- `statsBrandPurchaseAmountSet` is a sorted set which tracks largest brand purchases
530+
531531
### Adding the function to Redis
532532
533533
We can add functions to Redis using various methods:
@@ -609,7 +609,7 @@ A sample command to add details to the stream:
609609
"XADD" "TRANSACTION_STREAM" "*" "action" "PAYMENT_PROCESSED" "userId" "USR_f0f00a86-7131" "orderDetails" "{'orderId':'bc438c5d-117e-41bd-97fa-943c03be0b1c','products':[],'paymentId':'clrrl8yp50007pf851m7f92u2'}" "transactionPipeline" "['PAYMENT_PROCESSED']"
610610
```
611611
612-
The `calculateStats` function listens to `TRANSACTION_STREAM` stream and updates the sales statistics accordingly.
612+
The `calculateStats` function listens to `TRANSACTION_STREAM` stream for `PAYMENT_PROCESSED` action and updates the sales statistics accordingly.
613613
614614
Check different stats variable values in RedisInsight which were used in trigger function `calculateStats`.
615615
![stream-trigger-test-ri](./images/stream-trigger-test-ri.png)
Loading
Loading
Loading
Loading
Loading

docs/howtos/solutions/vector/video-qa/index-video-qa.mdx

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: index-video-qa
33
title: Building an AI-Powered Video Q&A Application with Redis and LangChain
44
sidebar_label: Building an AI-Powered Video Q&A Application with Redis and LangChain
5-
slug: /howtos/solutions/vector/building-an-ai-powered-video-qa-application-with-redis-and-langchain
5+
slug: /howtos/solutions/vector/ai-qa-videos-langchain-redis-openai-google
66
authors: [prasan, will]
77
---
88

@@ -45,11 +45,89 @@ Our application leverages these technologies to create a unique Q&A platform bas
4545

4646
Here's how our application uses AI and semantic vector search to answer user questions based on video content:
4747

48-
1. **Uploading videos**: Users can upload YouTube videos either via links (e.g. `https://www.youtube.com/watch?v=LaiQFZ5bXaM`) or video IDs (e.g. `LaiQFZ5bXaM`). The application processes these inputs to retrieve necessary video information.
49-
1. **Video processing and AI interaction**: Using the [Youtube Data API](https://developers.google.com/youtube/v3), the application obtains video `titles`, `descriptions`, and `thumbnails`. It also uses [SearchAPI.io](https://searchapi.io) to retrieve video transcripts. These transcripts are then passed to a large language model (LLM) - either Google Gemini or OpenAI's ChatGPT - for summarization and sample question generation. The LLM also generates vector embeddings for these summaries.
50-
1. **Data storage with Redis**: All generated data, including video summaries, potential questions, and vector embeddings, are stored in Redis. The app utilizes Redis's diverse data types for efficient data handling, caching, and quick retrieval.
51-
1. **Search and answer retrieval**: The frontend, built with Next.js, allows users to ask questions. The application then searches the Redis database using semantic vector similarity to find relevant video content. It further uses the LLM to formulate answers, prioritizing information from video transcripts.
52-
1. **Presentation of results**: The app displays the most relevant videos along with the AI-generated answers, offering a comprehensive and interactive user experience. It also displays cached results from previous queries using semantic vector caching for faster response times.
48+
1. **Uploading videos**: Users can upload YouTube videos either via links (e.g. `https://www.youtube.com/watch?v=LaiQFZ5bXaM`) or video IDs (e.g. `LaiQFZ5bXaM`). The application processes these inputs to retrieve necessary video information. For the purposes of this tutorial, the app is pre-seeded with a collection of videos from the [Redis YouTube channel](https://www.youtube.com/@Redisinc).
49+
50+
![Upload videos screenshot](./images/upload-videos.png).
51+
52+
2. **Video processing and AI interaction**: Using the [Youtube Data API](https://developers.google.com/youtube/v3), the application obtains video `titles`, `descriptions`, and `thumbnails`. It also uses [SearchAPI.io](https://searchapi.io) to retrieve video transcripts. These transcripts are then passed to a large language model (LLM) - either Google Gemini or OpenAI's ChatGPT - for summarization and sample question generation. The LLM also generates vector embeddings for these summaries.
53+
54+
An example summary and sample questions generated by the LLM are shown below:
55+
56+
```text title="https://www.youtube.com/watch?v=LaiQFZ5bXaM"
57+
Summary:
58+
The video provides a walkthrough of building a real-time stock tracking application
59+
using Redis Stack, demonstrating its capability to handle multiple data models and
60+
act as a message broker in a single integrated database. The application maintains
61+
a watch list of stock symbols, along with real-time trading information and a chart
62+
updated with live data from the Alpaca API. The presenter uses Redis Stack features
63+
such as sets, JSON documents, time series, Pub/Sub, and Top-K filter to store and
64+
manage different types of data. An architecture diagram is provided, explaining the
65+
interconnection between the front end, API service, and streaming service within
66+
the application. Code snippets highlight key aspects of the API and streaming
67+
service written in Python, highlighting the use of Redis Bloom, Redis JSON, Redis
68+
Time Series, and Redis Search for managing data. The video concludes with a
69+
demonstration of how data structures are visualized and managed in RedisInsight,
70+
emphasizing how Redis Stack can simplify the building of a complex real-time
71+
application by replacing multiple traditional technologies with one solution.
72+
73+
Example Questions and Answers:
74+
75+
Q1: What is Redis Stack and what role does it play in the application?
76+
A1: Redis Stack is an extension to Redis that adds additional modules, turning it
77+
into a multi-model database. In the application, it is used for storing various
78+
types of data and managing real-time communication between microservices.
79+
80+
Q2: How is the stock watch list stored and managed within the application?
81+
A2: The watch list is stored as a Redis set which helps automatically prevent
82+
duplicate stock symbols. In addition, further information about each stock is
83+
stored in JSON documents within Redis Stack.
84+
85+
Q3: What type of data does the application store using time series capabilities of
86+
Redis Stack?
87+
A3: The application uses time series data to store and retrieve the price movements
88+
of the stocks, making it easy to query over a date range and to visualize chart
89+
data with time on the x-axis.
90+
91+
Q4: Can you explain the use of the Top-K filter in the application?
92+
A4: The Top-K filter is a feature of Redis Bloom that is used to maintain a
93+
leaderboard of the most frequently traded stocks on the watch list, updating every
94+
minute with the number of trades that happen.
95+
96+
Q5: What methods are used to update the front end with real-time information in
97+
the application?
98+
A5: WebSockets are used to receive real-time updates for trending stocks, trades,
99+
and stock bars from the API service, which, in turn, receives the information from
100+
Redis Pub/Sub messages generated by the streaming service.
101+
102+
Q6: How does the application sync the watch list with the streaming service?
103+
A6: The application listens to the watch list key space in Redis for updates. When
104+
a stock is added or removed from the watch list on the front end, the API
105+
communicates this to Redis, and the streaming service then subscribes or
106+
unsubscribes to updates from the Alpaca API for that stock.
107+
108+
Q7: What frontend technologies are mentioned for building the UI of the application?
109+
A7: The UI service for the front end is built using Tailwind CSS, Chart.js, and
110+
Next.js, which is a typical tech stack for creating a modern web application.
111+
112+
Q8: How does Redis Insight help in managing the application data?
113+
A8: Redis Insight provides a visual interface to see and manage the data structures
114+
used in Redis Stack, including JSON documents, sets, and time series data related
115+
to the stock information in the application.
116+
```
117+
118+
3. **Data storage with Redis**: All generated data, including video summaries, potential questions, and vector embeddings, are stored in Redis. The app utilizes Redis's diverse data types for efficient data handling, caching, and quick retrieval.
119+
120+
![RedisInsight keys](./images/redisinsight-keys.png)
121+
122+
4. **Search and answer retrieval**: The frontend, built with Next.js, allows users to ask questions. The application then searches the Redis database using semantic vector similarity to find relevant video content. It further uses the LLM to formulate answers, prioritizing information from video transcripts.
123+
124+
125+
![Asking a question](./images/ask-question.png)
126+
127+
5. **Presentation of results**: The app displays the most relevant videos along with the AI-generated answers, offering a comprehensive and interactive user experience. It also displays cached results from previous queries using semantic vector caching for faster response times.
128+
129+
130+
![Existing answers](./images/video-qa-existing-answer.png)
53131

54132
## Setting Up the Environment
55133

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ module.exports = {
398398
'howtos/solutions/vector/gen-ai-chatbot/index-solutions-gen-ai-chatbot',
399399
'howtos/solutions/vector/semantic-text-search/index-semantic-text-search',
400400
'howtos/solutions/vector/image-summary-search/index-image-summary-search',
401+
'howtos/solutions/vector/video-qa/index-video-qa'
401402
],
402403
},
403404
{

0 commit comments

Comments
 (0)