|
| 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) |
0 commit comments