@sf-ai/sdk
v0.2.1
Published
Type-safe SDK for the San Francisco database with GraphQL codegen
Maintainers
Readme
@sf-ai/sdk
Type-safe SDK for the San Francisco database with GraphQL codegen.
Overview
This package provides a type-safe SDK generated from the San Francisco RAG database schema using @constructive-io/graphql-codegen. It generates both React Query hooks and a Prisma-like ORM client from the PGPM modules.
Installation
pnpm add @sf-ai/sdkUsage
ORM Client
import { createClient } from '@sf-ai/sdk';
const db = createClient({
endpoint: process.env.GRAPHQL_ENDPOINT,
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
},
});
// Query documents
const documents = await db.document.findMany({
select: { id: true, title: true, content: true },
first: 10,
}).execute().unwrap();
// Query chunks with embeddings
const chunks = await db.chunk.findMany({
select: {
id: true,
content: true,
document: { select: { id: true, title: true } },
},
}).execute().unwrap();React Query Hooks
import { useDocumentsQuery, useChunksQuery } from '@sf-ai/sdk';
function DocumentList() {
const { data, isLoading } = useDocumentsQuery({ first: 10 });
if (isLoading) return <div>Loading...</div>;
return (
<ul>
{data?.documents.nodes.map((doc) => (
<li key={doc.id}>{doc.title}</li>
))}
</ul>
);
}Regenerating the SDK
The SDK is generated from the PGPM modules in this repository. To regenerate:
Locally
Requires a running PostgreSQL database with the schema deployed:
cd packages/sf-sdk
pnpm run codegen:allVia GitHub Actions
Use the "Generate SDK" workflow which:
- Spins up an ephemeral PostgreSQL database
- Deploys the PGPM modules
- Generates the SDK types
- Optionally commits the changes
Run the workflow from the Actions tab with the "commit_changes" option enabled to automatically commit regenerated types.
Configuration
The codegen configuration is in graphql-codegen.config.ts:
import { defineConfig } from '@constructive-io/graphql-codegen';
export default defineConfig({
targets: {
default: {
db: {
pgpm: {
modulePath: '../rag-core',
},
schemas: ['rag'],
},
output: './src/generated',
// ... other options
},
},
});Schema
The SDK is generated from the rag schema which includes:
embedding_model- Embedding model configurationscollection- Document collectionscollection_model- Collection-model associationsdocument- Full documentschunk- Document chunks for RAGembedding- Vector embeddings
