Class ConvexVectorStore<DataModel, TableName, IndexName, TextFieldName, EmbeddingFieldName, MetadataFieldName, InsertMutation, GetQuery>

Class that is a wrapper around Convex storage and vector search. It is used to insert embeddings in Convex documents with a vector search index, and perform a vector search on them.

ConvexVectorStore does NOT implement maxMarginalRelevanceSearch.

Type Parameters

  • DataModel extends GenericDataModel
  • TableName extends TableNamesInDataModel<DataModel>
  • IndexName extends VectorIndexNames<NamedTableInfo<DataModel, TableName>>
  • TextFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>
  • EmbeddingFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>
  • MetadataFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>
  • InsertMutation extends FunctionReference<"mutation", "internal", {
        document: object;
        table: string;
    }>
  • GetQuery extends FunctionReference<"query", "internal", {
        id: string;
    }, object | null>

Hierarchy

  • VectorStore
    • ConvexVectorStore

Constructors

Properties

FilterType: {
    filter?: ((q: VectorFilterBuilder<GenericDocument, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>);
    includeEmbeddings?: boolean;
}

Type that defines the filter used in the similaritySearchVectorWithScore and maxMarginalRelevanceSearch methods. It includes limit, filter and a flag to include embeddings.

embeddings: EmbeddingsInterface

Methods

  • Add documents to the Convex table. It first converts the documents to vectors using the embeddings and then calls the addVectors method.

    Parameters

    • documents: Document<Record<string, any>>[]

      Documents to be added.

    Returns Promise<void>

    Promise that resolves when the documents have been added.

  • Add vectors and their corresponding documents to the Convex table.

    Parameters

    • vectors: number[][]

      Vectors to be added.

    • documents: Document<Record<string, any>>[]

      Corresponding documents to be added.

    Returns Promise<void>

    Promise that resolves when the vectors and documents have been added.

  • Parameters

    • Optional_params: Record<string, any>

    Returns Promise<void>

  • Return documents selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to the query AND diversity among selected documents.

    Parameters

    • query: string

      Text to look up documents similar to.

    • options: MaxMarginalRelevanceSearchOptions<{
          filter?: ((q: VectorFilterBuilder<GenericDocument, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>);
          includeEmbeddings?: boolean;
      }>
    • _callbacks: undefined | Callbacks

    Returns Promise<DocumentInterface<Record<string, any>>[]>

    • List of documents selected by maximal marginal relevance.
  • Parameters

    • query: string
    • Optionalk: number
    • Optionalfilter: {
          filter?: ((q: VectorFilterBuilder<GenericDocument, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>);
          includeEmbeddings?: boolean;
      }
      • Optionalfilter?: ((q: VectorFilterBuilder<GenericDocument, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>)
          • (q): FilterExpression<boolean>
          • Parameters

            Returns FilterExpression<boolean>

      • OptionalincludeEmbeddings?: boolean
    • Optional_callbacks: Callbacks

    Returns Promise<DocumentInterface<Record<string, any>>[]>

  • Similarity search on the vectors stored in the Convex table. It returns a list of documents and their corresponding similarity scores.

    Parameters

    • query: number[]

      Query vector for the similarity search.

    • k: number

      Number of nearest neighbors to return.

    • Optionalfilter: {
          filter?: ((q: VectorFilterBuilder<GenericDocument, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>);
          includeEmbeddings?: boolean;
      }

      Optional filter to be applied.

      • Optionalfilter?: ((q: VectorFilterBuilder<GenericDocument, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>)
          • (q): FilterExpression<boolean>
          • Parameters

            Returns FilterExpression<boolean>

      • OptionalincludeEmbeddings?: boolean

    Returns Promise<[Document<Record<string, any>>, number][]>

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Parameters

    • query: string
    • Optionalk: number
    • Optionalfilter: {
          filter?: ((q: VectorFilterBuilder<GenericDocument, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>);
          includeEmbeddings?: boolean;
      }
      • Optionalfilter?: ((q: VectorFilterBuilder<GenericDocument, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>)
          • (q): FilterExpression<boolean>
          • Parameters

            Returns FilterExpression<boolean>

      • OptionalincludeEmbeddings?: boolean
    • Optional_callbacks: Callbacks

    Returns Promise<[DocumentInterface<Record<string, any>>, number][]>

  • Returns Serialized