Skip to content

Commit 4848ec2

Browse files
authored
Moving createVectorIndexer Firebase Functions to V2 (#2281)
* Moving createVectorIndexer firebase functions to V2 * Enable the vector indexing trigger functions
1 parent 7bd6603 commit 4848ec2

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

‎functions/src/bills/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./bills"
33
export * from "./search"
44
export * from "./updateBillReferences"
55
export * from "./updateBillSearchIndex"
6+
export * from "./vector"

‎functions/src/index.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export {
77
syncBillToSearchIndex,
88
updateBillReferences,
99
updateBillSearchIndex,
10-
upgradeBillSearchIndex
10+
upgradeBillSearchIndex,
11+
syncBillToVectorIndex
1112
} from "./bills"
1213
export { updateBillTracker } from "./analysis"
1314
export { fetchCityBatch, startCityBatches } from "./cities"
@@ -41,7 +42,8 @@ export {
4142
runTestimonyBackfillChunk,
4243
syncTestimonyToSearchIndex,
4344
upgradeTestimonySearchIndex,
44-
resolveReportV2 as adminResolveReportV2
45+
resolveReportV2 as adminResolveReportV2,
46+
syncTestimonyToVectorIndex
4547
} from "./testimony"
4648
export {
4749
publishNotifications,
@@ -67,6 +69,8 @@ export { transcriptionV2 } from "./webhooks"
6769
export { matchOcpfMembersV2 } from "./ocpf/matchOcpfMembers"
6870
export { scrapeOcpfFinanceV2 } from "./ocpf/scrapeOcpfFinance"
6971

72+
export { syncBallotQuestionToVectorIndex } from "./ballotQuestions/vector"
73+
7074
export * from "./triggerPubsubFunction"
7175

7276
export { mcpProxyV2 } from "./mcp/proxy"

‎functions/src/search/createVectorIndexer.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { runWith } from "firebase-functions"
1+
import { onDocumentWritten } from "firebase-functions/v2/firestore"
22
import * as admin from "firebase-admin"
33
import { FieldValue } from "firebase-admin/firestore"
44
import { PredictionServiceClient, helpers } from "@google-cloud/aiplatform"
@@ -16,12 +16,15 @@ export function createVectorIndexer(config: VectorIndexerConfig) {
1616
const publisher = "google"
1717
const model = "text-embedding-005"
1818

19-
return runWith({
20-
timeoutSeconds: 60,
21-
memory: "512MB"
22-
})
23-
.firestore.document(config.documentTrigger)
24-
.onWrite(async change => {
19+
return onDocumentWritten(
20+
{
21+
document: config.documentTrigger,
22+
timeoutSeconds: 60,
23+
memory: "512MiB"
24+
},
25+
async event => {
26+
const change = event.data
27+
if (!change) return
2528
const data = change.after.exists ? change.after.data() : null
2629
if (!data) return // Deleted
2730

@@ -103,5 +106,6 @@ export function createVectorIndexer(config: VectorIndexerConfig) {
103106
[config.vectorField]: fieldValue.vector(embedding),
104107
[`${config.vectorField}_hash`]: textHash // Store hash to track changes
105108
})
106-
})
109+
}
110+
)
107111
}

‎functions/src/testimony/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./deleteTestimony"
22
export * from "./publishTestimony"
33
export * from "./search"
44
export * from "./resolveReport"
5+
export * from "./vector"

0 commit comments

Comments
 (0)