What's the easiest way to return a full document from Firestore in this retriever (screenshot from Genkit docs)?
My best guess is in the metadata field, so doing something like:
const vectorQuerySnapshot = await vectorQuery.get();
return {
documents: vectorQuerySnapshot.docs.map((doc) =>
// doc.data() represents the Firestore document. You may process it as needed to generate
// a Genkit document object, depending on your storage format.
Document.fromText(doc.data().title.title_original, doc.data())
),
};
Document metadata in Genkit is expected to be a Record<string, any> type object. If Firestore's DocumentSnapshot.data() method returns a compatible object, your solution works.
You could also include the Firestore doc in a self-declared "special" field in the metadata (eg: { full_firestore_doc: doc.data() }). This separates your actual Firestore doc from other metadata fields that you may want to include along with your Genkit document.
If you want to include more than title.title_original in your Genkit Document text, you can create a new string with the fields that you want to include and set it as the text. Eg:
vectorQuerySnapshot.docs.map((doc) => {
const text = `Title: ${doc.title.title_original}\nSomething else: ${doc.other_field}`
return Document.fromText(text, {full_document: doc})
}),
Hope this helps!
References:
1 Genkit Document
2 Firestore DocumentSnapshot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With