Skip to content

Commit 8216053

Browse files
authored
chore: rag funcs example (#793)
Adds an example of using RAG, alongside the OpenAI pattern for search extensions. https://linear.app/speakeasy/issue/AGE-733/guide-rag-with-gram-functions
1 parent b8ed917 commit 8216053

File tree

9 files changed

+5379
-0
lines changed

9 files changed

+5379
-0
lines changed

examples/functions-rag/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
dist
3+
.env
4+
.DS_Store
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
pnpm-debug.log*
9+
*.tsbuildinfo
10+
gram.deploy.json

examples/functions-rag/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Gram Functions: RAG Integration with Ragie
2+
3+
This example demonstrates real-world patterns for building [Gram
4+
Functions](https://www.speakeasy.com/docs/gram/gram-functions/introduction) that
5+
implement RAG (Retrieval-Augmented Generation) workflows. Study this project to
6+
learn how to structure document management and semantic search tools with proper
7+
API integration, validation, and data transformation.
8+
9+
## What's Included
10+
11+
**Document Management Tools**
12+
13+
- `list_partitions` - Lists document partitions in your Ragie account. Demonstrates filtering and pagination patterns.
14+
- `upload_file` - Uploads documents from local file paths. Demonstrates file handling and blob operations.
15+
- `upload_url` - Ingests documents from URLs. Demonstrates asynchronous document processing.
16+
- `upload_text` - Creates documents from raw text. Demonstrates programmatic content indexing.
17+
18+
**Search and Retrieval Tools**
19+
20+
- `search` - Performs semantic RAG search across indexed documents. Demonstrates vector search integration with configurable ranking.
21+
- `fetch` - Downloads document content by ID. Demonstrates content retrieval with metadata extraction.
22+
23+
## Key Patterns
24+
25+
- **Type-safe validation** with Zod schemas for all inputs
26+
- **Environment variable management** for secure API key handling
27+
- **External API integration** using the Ragie SDK
28+
- **Document lifecycle workflows** from upload to search to retrieval
29+
- **RAG search implementation** with ranking and filtering capabilities
30+
- **Metadata handling** for document organization and tracking
31+
32+
## Quick start
33+
34+
To get started, install dependencies and run the development server:
35+
36+
```bash
37+
npm install
38+
```
39+
40+
To build a zip file that can be deployed to Gram, run:
41+
42+
```bash
43+
npm build
44+
```
45+
46+
After building, push your function to Gram with:
47+
48+
```bash
49+
npm push
50+
```
51+
52+
## Testing Locally
53+
54+
If you want to poke at the tools you've built during local development, you can
55+
start a local MCP server over stdio transport with:
56+
57+
```bash
58+
npm dev
59+
```
60+
61+
Specifically, this command will spin up [MCP inspector][mcp-inspector] to let
62+
you interactively test your tools.
63+
64+
[mcp-inspector]: https://github.com/modelcontextprotocol/inspector
65+
66+
## Learn More
67+
68+
- [Gram Functions Documentation](https://www.speakeasy.com/docs/gram/gram-functions/introduction)
69+
- [Framework API Reference](./CONTRIBUTING.md)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from "@gram-ai/functions/build";
2+
3+
export default defineConfig({
4+
openBrowserAfterDeploy: false,
5+
});

0 commit comments

Comments
 (0)