We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
firebase-tools: 13.29.1 Platform: macOS
import { Response } from "express"; import * as functions from "firebase-functions/v2"; import { firestore } from "firebase-admin"; import { FieldPath, FieldValue } from "firebase-admin/firestore"; import * as admin from "firebase-admin"; export const defaultApp = admin.initializeApp(); defaultApp; export const setUpUsers = functions.https.onRequest(handler(async () => { await firestore().collection("users").doc("user1").set({ field: { deep: FieldValue.vector([1.0, 2.0]), }, fieldShallow: FieldValue.vector([1.0, 2.0]), }); return 'Set user'; })); export const search = functions.https.onRequest(handler(async () => { return { deepField: await searchForUsers('field.deep'), deepFieldDirect: await searchForUsers(new FieldPath('field', 'deep')), shallowField: await searchForUsers('fieldShallow'), }; })); async function searchForUsers(path: FieldPath | string): Promise<number> { const results = await firestore().collection("users").findNearest({ distanceMeasure: "EUCLIDEAN", queryVector: FieldValue.vector([1.0, 2.0]), limit: 10, vectorField: path, }).get(); return results.size; } function handler( callback: () => Promise<any> ): (request: functions.https.Request, response: Response) => Promise<void> { return async (_, response) => { try { const result = await callback(); response.json({ result }); response.end(); } catch (error) { console.log(error); response.status(500); response.end(); } }; }
{ "name": "functions", "scripts": { "build": "tsc", "build:watch": "tsc --watch", "serve": "npm run build && firebase emulators:start --only functions", "shell": "npm run build && firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "engines": { "node": "20" }, "main": "lib/index.js", "dependencies": { "firebase-admin": "^13.0.0", "firebase-functions": "^6.0.1" }, "devDependencies": { "typescript": "^5.0.0" }, "private": true }
firebase init
firebase emulators:start --project demo-project
http://127.0.0.1:5001/demo-project/us-central1/setUpUsers
http://127.0.0.1:5001/demo-project/us-central1/search
The expected output of the function is:
{ "result": { "deepField": 1, "deepFieldDirect": 1, "shallowField": 1 } }
(This is the output produced when running against the live instance.)
The output of the function is:
{ "result": { "deepField": 0, "deepFieldDirect": 0, "shallowField": 1 } }
It seems the emulator doesn't handle nested vector fields.
The text was updated successfully, but these errors were encountered:
There was an issue with nested vector fields, before googleapis/nodejs-firestore#2081 Linking in case it helps.
Sorry, something went wrong.
No branches or pull requests
[REQUIRED] Environment info
firebase-tools: 13.29.1
Platform: macOS
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
firebase init
firebase emulators:start --project demo-project
http://127.0.0.1:5001/demo-project/us-central1/setUpUsers
in browserhttp://127.0.0.1:5001/demo-project/us-central1/search
[REQUIRED] Expected behavior
The expected output of the function is:
(This is the output produced when running against the live instance.)
[REQUIRED] Actual behavior
The output of the function is:
It seems the emulator doesn't handle nested vector fields.
The text was updated successfully, but these errors were encountered: