• Define a retriever that uses vector similarity search to retrieve documents from Firestore. You must create a vector index on the associated field before you can perform nearest-neighbor search.

    Parameters

    • ai: Genkit
    • config: {
          collection?: string;
          contentField:
              | string
              | (
                  snap: QueryDocumentSnapshot<DocumentData, DocumentData>,
              ) => (
                  | {
                      custom?: Record<string, unknown>;
                      data?: unknown;
                      media?: undefined;
                      metadata?: Record<string, unknown>;
                      text: string;
                      toolRequest?: undefined;
                      toolResponse?: undefined;
                  }
                  | {
                      custom?: Record<string, unknown>;
                      data?: unknown;
                      media: { contentType?: string; url: string };
                      metadata?: Record<string, unknown>;
                      text?: undefined;
                      toolRequest?: undefined;
                      toolResponse?: undefined;
                  }
              )[];
          distanceMeasure?: "EUCLIDEAN"
          | "COSINE"
          | "DOT_PRODUCT";
          distanceResultField?: string;
          distanceThreshold?: number;
          embedder: EmbedderArgument<z.ZodTypeAny>;
          firestore: Firestore;
          label?: string;
          metadataFields?:
              | string[]
              | (
                  snap: QueryDocumentSnapshot<DocumentData, DocumentData>,
              ) => Record<string, any>;
          name: string;
          vectorField: string;
      }
      • Optionalcollection?: string

        The name of the collection from which to query.

      • contentField:
            | string
            | (
                snap: QueryDocumentSnapshot<DocumentData, DocumentData>,
            ) => (
                | {
                    custom?: Record<string, unknown>;
                    data?: unknown;
                    media?: undefined;
                    metadata?: Record<string, unknown>;
                    text: string;
                    toolRequest?: undefined;
                    toolResponse?: undefined;
                }
                | {
                    custom?: Record<string, unknown>;
                    data?: unknown;
                    media: { contentType?: string; url: string };
                    metadata?: Record<string, unknown>;
                    text?: undefined;
                    toolRequest?: undefined;
                    toolResponse?: undefined;
                }
            )[]

        The name of the field containing the document content you wish to return.

      • OptionaldistanceMeasure?: "EUCLIDEAN" | "COSINE" | "DOT_PRODUCT"

        The distance measure to use when comparing vectors. Defaults to 'COSINE'.

      • OptionaldistanceResultField?: string

        Optionally specifies the name of a metadata field that will be set on each returned Document, which will contain the computed distance for the document.

      • OptionaldistanceThreshold?: number

        Specifies a threshold for which no less similar documents will be returned. The behavior of the specified distanceMeasure will affect the meaning of the distance threshold.

        • For distanceMeasure: "EUCLIDEAN", the meaning of distanceThreshold is: SELECT docs WHERE euclidean_distance <= distanceThreshold
        • For distanceMeasure: "COSINE", the meaning of distanceThreshold is: SELECT docs WHERE cosine_distance <= distanceThreshold
        • For distanceMeasure: "DOT_PRODUCT", the meaning of distanceThreshold is: SELECT docs WHERE dot_product_distance >= distanceThreshold
      • embedder: EmbedderArgument<z.ZodTypeAny>

        The embedder to use with this retriever.

      • firestore: Firestore

        The Firestore database instance from which to query.

      • Optionallabel?: string

        Optional label for display in Developer UI.

      • OptionalmetadataFields?:
            | string[]
            | (
                snap: QueryDocumentSnapshot<DocumentData, DocumentData>,
            ) => Record<string, any>

        A list of fields to include in the returned document metadata. If not supplied, all fields other than the vector are included. Alternatively, provide a transform function to extract the desired metadata fields from a snapshot.

      • name: string

        The name of the retriever.

      • vectorField: string

        The name of the field within the collection containing the vector data.

    Returns RetrieverAction