Skip to content

Conversation

@Pelleking
Copy link

feat(firestore): add VectorValue type and vector() API

Adds Firestore Vector field support to React Native Firebase:

  • New VectorValue class and vector(values?: number[]) constructor
  • End-to-end JS ↔ native serialization/deserialization (iOS/Android) and web-fallback
  • Modular and namespaced surfaces

Motivation

Brings RNFB Firestore to parity with Firebase SDKs that added Vector support:

API

  • Modular:
    • import { VectorValue, vector } from '@react-native-firebase/firestore'
    • Example: await setDoc(docRef, { embedding: vector([0.1, 0.2, 0.3]) })
  • Namespaced:
    • firebase.firestore.VectorValue, firebase.firestore.vector(values)

Implementation

  • JS runtime: VectorValue with validation, isEqual, toJSON
  • Type map: added vector type; wired into generateNativeData and parseNativeData
  • Web fallback: maps to JS SDK VectorValue in web/convert.js
  • iOS bridge: reflective detection/creation of FIRVectorValue (no hard crash on older SDKs)
  • Android bridge: reflective detection/creation of com.google.firebase.firestore.VectorValue
  • Typings: VectorValue type and vector() declaration; added to DocumentFieldType
  • Tests: unit test covers construction and serializer round-trip

Minimum native versions for full functionality:

  • iOS Firestore ≥ 11.10.0
  • Android Firestore ≥ 25.1.0
    Older SDKs won’t crash (reflection guards), but vectors will not function.

Usage Example

import firestore, { vector } from '@react-native-firebase/firestore';

await firestore()
  .doc(`users/${userId}/todo/${page.id}/items/${id}`)
  .set({
    text: todoText,
    done: false,
    createdAt: now,
    embedding: vector([0.12, 0.34, 0.56]),
  });

const snap = await firestore().doc(`users/${userId}/todo/${page.id}/items/${id}`).get();
const v = snap.get('embedding'); // VectorValue
console.log('read vector:', v.values);

Tests

  • Jest unit: packages/firestore/__tests__/vector.test.ts
  • Validates construction, equality, serializer round-trip (JS ↔ native type map)

Types

  • Updated packages/firestore/lib/index.d.ts to include VectorValue, vector(), and DocumentFieldType union

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.

    • Yes
  • My change supports the following platforms;

    • Android
    • iOS
    • Other (web)
  • My change includes tests;

    • e2e tests added or updated in packages/**/e2e
    • jest tests added or updated in packages/**/__tests__
  • I have updated TypeScript types that are affected by my change.

  • This is a breaking change;

    • Yes
    • No

Notes

  • Bridges use reflection to avoid hard dependency on newer native symbols at build time.
  • If project native SDKs are older than the minimums above, vector fields won’t be usable (graceful no-op).

@vercel
Copy link

vercel bot commented Oct 31, 2025

@Pelleking is attempting to deploy a commit to the Invertase Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Oct 31, 2025

CLA assistant check
All committers have signed the CLA.

@Pelleking
Copy link
Author

The issue it resolves #8442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants