Generative AI
and LangStream.ai
December, 2023
Stream Meet @Bigbasket
Jauneet Singh
©2023 DataStax. – All rights reserved
About myself
2
Jauneet Singh
©2023 DataStax. – All rights reserved
GenAI is changing the industry landscape
3
©2023 DataStax. – All rights reserved
Prompting
4
Using GenAI is just about building a prompt
©2023 DataStax. – All rights reserved
Anatomy of a prompt
5
Problem to Solve:�Eg: “Should we propose a reduction coupon to the user ?”
©2023 DataStax. – All rights reserved
Anatomy of a prompt
6
Problem to Solve:�Eg: “Should we propose a reduction coupon to the user ?”
Dynamic data:
Eg: “user payment history, item price, item stock, …”
Aggregate structured data from multiple sources in real-time.
Event-Driven Architectures are a perfect match for this.
©2023 DataStax. – All rights reserved
Anatomy of a prompt
7
Problem to Solve:�Eg: “Should we propose a reduction coupon to the user ?”
Dynamic data (RAG):
Eg: “user payment history, item price, item stock, …”
Domain specific rules:
Eg: “rules to propose a reduction”
Data to solve the problem that was not used during the training.
©2023 DataStax. – All rights reserved
Anatomy of a prompt
8
Problem to Solve:�Eg: “Should we propose a reduction coupon to the user ?”
Dynamic data:
Eg: “user payment history, item price, item stock, …”
Domain specific data:
Eg: “rules to propose a reduction”
Limited size.�For OpenAI’s gpt-3.5-turbo: 4097 tokens (token ~= word)
For OpenAI’s gpt-3.5-turbo-16k: 16385 tokens
gpt-4-32k: 32,768
gpt-4-turbo: 128,000
©2023 DataStax. – All rights reserved
Problem: the domain specific data is huge and doesn’t fit into the LLM prompt.
9
©2023 DataStax. – All rights reserved
©2023 DataStax. – All rights reserved
What is a vector/embedding ?
10
v1
v2
v3
x
y
0
1
1
2 dimensions normalised vectors
©2023 DataStax. – All rights reserved
What is a vector/embedding ?
11
cat
dog
house
x
y
0
©2023 DataStax. – All rights reserved
Vector Search
12
Vector stores / vector databases
©2023 DataStax. – All rights reserved
Let’s go back to the problem: our domain specific data is huge and doesn’t fit into the LLM prompt.
13
©2023 DataStax. – All rights reserved
©2023 DataStax. – All rights reserved
Retrieval Augmented Generation (RAG)
14
Domain specific data
Vector
Database
(eg Astra, Pinecone)
Embeddings model
(eg OpenAI)
Compute embeddings
Prompt question
Compute embedding
Similarity search
Build a prompt
Store embeddings
Query the LLM
LLM
(eg OpenAI)
©2023 DataStax. – All rights reserved
Realtime Generative AI
15
Data
Streaming system (Kafka, Pulsar, …)
Web site crawling
Database
S3 / Block storage
Micro-service
©2023 DataStax. – All rights reserved
©2023 DataStax. – All rights reserved
Realtime Generative AI
16
Unstructured data
Extract text (eg. from PDF, HTML, MS doc)
Normalise (lower case, trim spaces)
Detect/filter/tag language
Text splitting
Data
Streaming system (Kafka, Pulsar, …)
Web site crawling
Database
S3 / Block storage
Micro-service
©2023 DataStax. – All rights reserved
©2023 DataStax. – All rights reserved
Realtime Generative AI
17
Structured data
Data manipulation
Conversion
Filtering
Flow control
Unstructured data
Extract text (eg. from PDF, HTML, ,MS doc)
Normalise (lower case, trim spaces)
Detect/filter/tag language
Text splitting
Data
Streaming system (Kafka, Pulsar, …)
Web site crawling
Database
S3 / Block storage
Micro-service
©2023 DataStax. – All rights reserved
©2023 DataStax. – All rights reserved
Realtime Generative AI
18
Structured data
Data manipulation
Conversion
Filtering
Flow control
Unstructured data
Extract text (eg. from PDF, HTML, ,MS doc)
Normalise (lower case, trim spaces)
Detect/filter/tag language
Text splitting
AI Operations
Compute embeddings
Store embeddings
Similarity search
Re-rank (MMR)
Chat/text completions (LLM)
Data
Streaming system (Kafka, Pulsar, …)
Web site crawling
Database
S3 / Block storage
Micro-service
©2023 DataStax. – All rights reserved
©2023 DataStax. – All rights reserved
Streaming
19
Streaming and Event Driven Architectures
©2023 DataStax. – All rights reserved
Here comes LangStream
20
©2023 DataStax. – All rights reserved
21
LLMs
Vector stores
AI libraries
Connectors
Messaging
©2023 DataStax. – All rights reserved
What is LangStream?
22
Open source
©2023 DataStax. – All rights reserved
What is LangStream?
23
Not just a library
©2023 DataStax. – All rights reserved
What is LangStream?
24
Rapid development and deployment
©2023 DataStax. – All rights reserved
What is LangStream?
25
Event-driven, real-time architecture
©2023 DataStax. – All rights reserved
High-Level Architecture
26
Kubernetes
Kafka
Agent�chat
completion
Vector DB
AI Services
Agent�OSS�embedding
LangStream
LangStream Operator
DB
Control Plane and API
WebSocket Gateway
©2023 DataStax. – All rights reserved
Agents
27
Source
Processor
Processor
Processor
KC
Sink
KC
built-in
built-in
built-in
Sources:
Sinks:
1 pod
Processors:
©2023 DataStax. – All rights reserved
Declarative low-code
28
topics:
- name: "input-topic"
creation-mode: create-if-not-exists
- name: "output-topic"
creation-mode: create-if-not-exists
pipeline:
- type: "document-to-json"
input: "input-topic"
configuration:
text-field: "question"
- type: "ai-chat-completions"
configuration:
model: "${secrets.open-ai.chat-completions-model}"
completion-field: "value.answer"
log-field: "value.prompt"
stream-to-topic: "output-topic"
stream-response-completion-field: "value"
min-chunks-per-message: 10
messages:
- role: user
content: "You are a helpful assistant. Below you can find a question from the user. Please try to help them the best way you can.\n\n{{% value.question}}"
Example application:
©2023 DataStax. – All rights reserved
Web Gateway
29
gateways:
- id: "user-input"
type: produce
topic: "${globals.questionsTopic}"
parameters:
- sessionId
authentication:
provider: github
configuration:
clientId: "${secrets.github.client-id}"
©2023 DataStax. – All rights reserved
Agenda
30
ChatBot with LangStream
E-Commerce recommendation service (LangChain)
Async e-Commerce recommendation service (LangChain + LangStream)
©2023 DataStax. – All rights reserved
©2023 DataStax. – All rights reserved
Build a ChatBot with LangStream
31
brew install LangStream/langstream/langstream
export OPEN_AI_ACCESS_KEY=<your-openai-api-key>
langstream docker run test -app https://github.com/LangStream/langstream/tree/main/examples/applications/docker-chatbot -s https://github.com/LangStream/langstream/blob/main/examples/secrets/secrets.yaml
©2023 DataStax. – All rights reserved
32
©2023 DataStax. – All rights reserved
E-Commerce recommendation service (LangChain)
33
©2023 DataStax. – All rights reserved
34
©2023 DataStax. – All rights reserved
Real time e-Commerce recommendation service (LangChain + LangStream)
35
©2023 DataStax. – All rights reserved
36
©2023 DataStax. – All rights reserved
Summary
37
Build and run Gen AI applications
Rapid development with no-code agents
Google Vertex AI, OpenAI, Hugging Face
Complements LangChain, LlamaIndex
Powered by Kubernetes, Kafka
Event-driven benefits
©2023 DataStax. – All rights reserved
©2023 DataStax. – All rights reserved
Thank You
©2023 DataStax. – All rights reserved