Skip to content

Commit 47ee2de

Browse files
committed
👌 IMPROVE: Chunker Example
1 parent 9eccd8d commit 47ee2de

File tree

2 files changed

+108
-14
lines changed

2 files changed

+108
-14
lines changed

examples/chunker/chunker.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import json
66
import os
7+
import pathlib
78

89
from dotenv import load_dotenv
910

@@ -23,22 +24,16 @@ def main():
2324
Chunks text content using Langbase.
2425
"""
2526
try:
26-
# Sample text content to chunk
27-
content = """Langbase is the most powerful serverless AI platform for building AI agents with memory.
28-
Build, deploy, and scale AI agents with tools and memory (RAG). Simple AI primitives with
29-
a world-class developer experience without using any frameworks.
30-
31-
With Langbase, you can compose multiple models together into pipelines. It's easier to
32-
think about, easier to develop for, and each pipe lets you choose which model to use for
33-
each task. You can see cost of every step. And allow your customers to hyper-personalize.
34-
35-
Maybe you want to use a smaller, domain-specific model for one task, and a larger
36-
general-purpose model for another task. Langbase makes it easy to use the right primitives
37-
and tools for each part of the job and provides developers with a zero-config composable
38-
AI infrastructure."""
27+
# Get the path to the document
28+
document_path = pathlib.Path(__file__).parent / "composable-ai.md"
3929

30+
# Read the file
31+
with open(document_path, "r", encoding="utf-8") as file:
32+
document_content = file.read()
4033
# Chunk the content
41-
chunks = lb.chunker(content=content, chunk_max_length=1024, chunk_overlap=256)
34+
chunks = lb.chunker(
35+
content=document_content, chunk_max_length=1024, chunk_overlap=256
36+
)
4237

4338
print(json.dumps(chunks, indent=2))
4439

examples/chunker/composable-ai.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Composable AI
2+
3+
## The Developer Friendly Future of AI Infrastructure
4+
5+
In software engineering, composition is a powerful concept. It allows for building complex systems from simple, interchangeable parts. Think Legos, Docker containers, React components. Langbase extends this concept to AI infrastructure with our **Composable AI** stack using [Pipes][pipe] and [Memory][memory].
6+
7+
---
8+
9+
## Why Composable AI?
10+
11+
**Composable and personalized AI**: With Langbase, you can compose multiple models together into pipelines. It's easier to think about, easier to develop for, and each pipe lets you choose which model to use for each task. You can see cost of every step. And allow your customers to hyper-personalize.
12+
13+
**Effortlessly zero-config AI infra**: Maybe you want to use a smaller, domain-specific model for one task, and a larger general-purpose model for another task. Langbase makes it easy to use the right primitives and tools for each part of the job and provides developers with a zero-config composable AI infrastructure.
14+
15+
That's a nice way of saying, *you get a unicorn-scale API in minutes, not months*.
16+
17+
> **The most common problem** I hear about in Gen AI space is that my AI agents are too complex and I can't scale them, too much AI talking to AI. I don't have control, I don't understand the cost, and the impact of this change vs that. Time from new model to prod is too long. Feels static, my customers can't personalize it. ⌘ Langbase fixes all this. — [AA](https://www.linkedin.com/in/MrAhmadAwais/)
18+
19+
---
20+
21+
## Interactive Example: Composable AI Email Agent
22+
23+
But how does Composable AI work?
24+
25+
Here's an interactive example of a composable AI Email Agent: Classifies, summarizes, responds. Click to send a spam or valid email and check how composable it is: Swap any pipes, any LLM, hyper-personalize (you or your users), observe costs. Everything is composable.
26+
27+
28+
29+
## Example: Composable AI Email Agent
30+
31+
32+
I have built an AI email agent that can read my emails, understand the sentiment, summarize, and respond to them. Let's break it down to how it works, hint several pipes working together to make smart personalized decisions.
33+
34+
1. I created a pipe: `email-sentiment` — this one reads my emails to understand the sentiment
35+
2. `email-summarizer` pipe — it summarizes my emails so I can quickly understand them
36+
3. `email-decision-maker` pipe — should I respond? is it urgent? is it a newsletter?
37+
4. If `email-decision-maker` pipe says *yes*, then I need to respond. This invokes the final pipe
38+
5. `email-writer` pipe — writes a draft response to my emails with one of the eight formats I have
39+
40+
41+
## Why Composable AI is powerful?
42+
43+
Ah, the power of composition. I can swap out any of these pipes with a new one.
44+
45+
- **Flexibility**: Swap components without rewriting everything
46+
- **Reusability**: Build complex systems from simple, tested parts
47+
- **Scalability**: Optimize at the component level for better performance
48+
- **Observability**: Monitor and debug each step of your AI pipeline
49+
50+
51+
### Control flow
52+
53+
- Maybe I want to use a different sentiment analysis model
54+
- Or maybe I want to use a different summarizer when I'm on vacation
55+
- I can chose a different LLM (small or large) based on the task
56+
- BTW I definitely use a different `decision-maker` pipe on a busy day.
57+
58+
### Extensibility
59+
60+
- **Add more when needed**: I can also add more pipes to this pipeline. Maybe I want to add a pipe that checks my calendar or the weather before I respond to an email. You get the idea. Always bet on composition.
61+
- **Eight Formats to write emails**: And I have several formats. Because Pipes are composable, I have eight different versions of `email-writer` pipe. I have a pipe `email-pick-writer` that picks the correct pipe to draft a response with. Why? I talk to my friends differently than my investors, reports, managers, vendors — you name it.
62+
63+
64+
### Long-term memory and context awareness
65+
66+
- By the way, I have all my emails in an `emails-store` memory, which any of these pipes can refer to if needed. That's managed [semantic RAG][memory] over all the emails I have ever received.
67+
- And yes, my `emails-smart-spam` memory knows all the pesky smart spam emails that I don't want to see in my inbox.
68+
69+
### Cost & Observability
70+
71+
- Because each intent and action is mapped out Pipe — which is an excellent primitive for using LLMs, I can see everything related to cost, usage, and effectiveness of each pipe. I can see how many emails were processed, how many were responded to, how many were marked as spam, etc.
72+
- I can switch LLMs for any of these actions, [fork a pipe][fork], and see how it performs. I can version my pipes and see how the new version performs against the old one.
73+
- And we're just getting started …
74+
75+
### Why Developers Love It
76+
77+
- **Modular**: Build, test, and deploy pipes x memorysets independently
78+
- **Extensible**: API-first no dependency on a single language
79+
- **Version Control Friendly**: Track changes at the pipe level
80+
- **Cost-Effective**: Optimize resource usage for each AI task
81+
- **Stakeholder Friendly**: Collaborate with your team on each pipe and memory. All your R&D team, engineering, product, GTM (marketing, sales), and even stakeholders can collaborate on the same pipe. It's like a Google Doc x GitHub for AI. That's what makes it so powerful.
82+
83+
---
84+
85+
Each pipe and memory are like a docker container. You can have any number of pipes and memorysets.
86+
87+
Can't wait to share more exciting examples of composable AI. We're cookin!!
88+
89+
We'll share more on this soon. Follow us on [Twitter][x] and [LinkedIn][li] for updates.
90+
91+
[pipe]: /pipe/
92+
[memory]: /memory
93+
[signup]: https://langbase.fyi/awesome
94+
[x]: https://twitter.com/LangbaseInc
95+
[li]: https://www.linkedin.com/company/langbase/
96+
[email]: mailto:[email protected]?subject=Pipe-Quickstart&body=Ref:%20https://langbase.com/docs/pipe/quickstart
97+
[fork]: https://langbase.com/docs/features/fork
98+
99+
---

0 commit comments

Comments
 (0)