langchain.js
    Preparing search index...

    PostgreSQL implementation of the BaseStore interface. This is now a lightweight orchestrator that delegates to specialized modules.

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Execute multiple operations in a single batch.

      Type Parameters

      • Op extends Operation[]

      Parameters

      • operations: Op

      Returns Promise<OperationResults<Op>>

    • Delete an item by namespace and key.

      Parameters

      • namespace: string[]
      • key: string

      Returns Promise<void>

    • Get an item by namespace and key.

      Parameters

      • namespace: string[]
      • key: string

      Returns Promise<any>

    • Get statistics about the store.

      Returns Promise<
          {
              expiredItems: number;
              namespaceCount: number;
              newestItem: null
              | Date;
              oldestItem: null | Date;
              totalItems: number;
          },
      >

    • Performs hybrid search combining vector similarity and text search.

      Parameters

      • namespacePrefix: string[]

        The namespace prefix to search within

      • query: string

        The text query to search for

      • options: {
            filter?: Record<string, unknown>;
            limit?: number;
            offset?: number;
            similarityThreshold?: number;
            vectorWeight?: number;
        } = {}

        Search options including filter, vector weight, and similarity threshold

      Returns Promise<SearchItem[]>

      Promise resolving to an array of search results with combined similarity scores

    • List namespaces with optional filtering.

      Parameters

      • options: {
            limit?: number;
            maxDepth?: number;
            offset?: number;
            prefix?: string[];
            suffix?: string[];
        } = {}

      Returns Promise<string[][]>

    • Put an item with optional indexing configuration and TTL.

      Parameters

      • namespace: string[]
      • key: string
      • value: Record<string, unknown>
      • Optionalindex: false | string[]
      • Optionaloptions: { ttl?: number }

      Returns Promise<void>

    • Search for items in the store with support for text search, vector search, and filtering.

      Parameters

      • namespacePrefix: string[]

        The namespace prefix to search within

      • options: {
            distanceMetric?: "cosine" | "l2" | "inner_product";
            filter?: Record<string, null | string | number | boolean | FilterOperators>;
            limit?: number;
            mode?: "text" | "vector" | "hybrid" | "auto";
            offset?: number;
            query?: string;
            refreshTtl?: boolean;
            similarityThreshold?: number;
            vectorWeight?: number;
        } = {}

        Search options including search mode, filters, query text, and pagination

        • OptionaldistanceMetric?: "cosine" | "l2" | "inner_product"

          Distance metric for vector search.

          "cosine"
          
        • Optionalfilter?: Record<string, null | string | number | boolean | FilterOperators>

          Filter conditions with support for advanced operators.

        • Optionallimit?: number

          Maximum number of results to return.

          10
          
        • Optionalmode?: "text" | "vector" | "hybrid" | "auto"

          Search mode.

          "auto"
          
        • Optionaloffset?: number

          Number of results to skip for pagination.

          0
          
        • Optionalquery?: string

          Natural language search query.

        • OptionalrefreshTtl?: boolean

          Whether to refresh TTL for returned items.

        • OptionalsimilarityThreshold?: number

          Similarity threshold for vector search.

        • OptionalvectorWeight?: number

          Weight for vector search in hybrid mode.

          0.7
          

      Returns Promise<SearchItem[]>

      Promise resolving to an array of search results with optional similarity scores

      // Basic text search
      const results = await store.search(["documents"], {
      query: "machine learning",
      mode: "text"
      });

      // Vector search
      const results = await store.search(["documents"], {
      query: "machine learning",
      mode: "vector",
      similarityThreshold: 0.7
      });

      // Hybrid search (combining vector and text)
      const results = await store.search(["documents"], {
      query: "machine learning",
      mode: "hybrid",
      vectorWeight: 0.7
      });

      // Filtered search
      const results = await store.search(["products"], {
      filter: { category: "electronics", price: { $lt: 100 } }
      });
    • Initialize the store by running migrations to create necessary tables and indexes.

      Returns Promise<void>

    • Start the store. Calls setup() if ensureTables is true.

      Returns Promise<void>

    • Stop the store and close all database connections.

      Returns Promise<void>

    • Manually sweep expired items from the store.

      Returns Promise<number>

    • Performs vector similarity search using embeddings.

      Parameters

      • namespacePrefix: string[]

        The namespace prefix to search within

      • query: string

        The text query to embed and search for similar items

      • options: {
            distanceMetric?: "cosine" | "l2" | "inner_product";
            filter?: Record<string, unknown>;
            limit?: number;
            offset?: number;
            similarityThreshold?: number;
        } = {}

        Search options including filter, similarity threshold, and distance metric

      Returns Promise<SearchItem[]>

      Promise resolving to an array of search results with similarity scores

    • Creates a PostgresStore instance from a connection string.

      Parameters

      Returns PostgresStore