Created
June 28, 2025 07:49
-
-
Save shangyilim/a624870f2085c1f75ce75c7371508b2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use server'; | |
/** | |
* @fileOverview Defines a Firestore retriever for the 'services' collection. | |
*/ | |
import { defineFirestoreRetriever } from '@genkit-ai/firebase'; | |
import { getFirestore } from 'firebase-admin/firestore'; | |
import { ai } from '@/ai/genkit'; | |
import type { ServiceItem } from '@/types'; | |
import { getFirebaseAdminApp } from '../firebase-service'; | |
const adminApp = getFirebaseAdminApp(); | |
const firestore = getFirestore(adminApp); | |
export const serviceRetriever = defineFirestoreRetriever(ai, { | |
name: 'serviceRetriever', | |
firestore, | |
collection: 'services', | |
contentField: 'description', // Primary text field for the document | |
vectorField: 'embedding', // Field containing vector embeddings | |
embedder: 'googleai/text-embedding-004', // Embedder used for querying | |
distanceMeasure: 'COSINE', | |
metadataFields: (snapshot)=> { | |
const data = snapshot.data() as ServiceItem; | |
return { | |
name: data.name, | |
description: data.description, | |
id: snapshot.id, | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment