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

Hierarchy (view full)

Constructors

Methods

  • 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<null | Item>

  • 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

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

      Search options including filter, vector weight, and similarity threshold

      • Optional filter?: Record<string, unknown>
      • Optional limit?: number
      • Optional offset?: number
      • Optional similarityThreshold?: number
      • Optional vectorWeight?: number

    Returns Promise<SearchItem[]>

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

  • List namespaces with optional filtering.

    Parameters

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

    Returns Promise<string[][]>

  • Put an item with optional indexing configuration and TTL.

    Parameters

    • namespace: string[]
    • key: string
    • value: Record<string, unknown>
    • Optional index: false | string[]
    • Optional options: {
          ttl?: number;
      }
      • Optional 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

    • Optional 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

      • Optional distanceMetric?: "cosine" | "l2" | "inner_product"

        Distance metric for vector search.

        Default

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

        Filter conditions with support for advanced operators.

      • Optional limit?: number

        Maximum number of results to return.

        Default

        10
        
      • Optional mode?: "text" | "vector" | "hybrid" | "auto"

        Search mode.

        Default

        "auto"
        
      • Optional offset?: number

        Number of results to skip for pagination.

        Default

        0
        
      • Optional query?: string

        Natural language search query.

      • Optional refreshTtl?: boolean

        Whether to refresh TTL for returned items.

      • Optional similarityThreshold?: number

        Similarity threshold for vector search.

      • Optional vectorWeight?: number

        Weight for vector search in hybrid mode.

        Default

        0.7
        

    Returns Promise<SearchItem[]>

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

    Example

    // 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

    • Optional 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

      • Optional distanceMetric?: "cosine" | "l2" | "inner_product"
      • Optional filter?: Record<string, unknown>
      • Optional limit?: number
      • Optional offset?: number
      • Optional similarityThreshold?: number

    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