*/ public static function available(): array { return [ 'vectorize' => __('Cloudflare Vectorize', 'aipcf-ai-provider-for-cloudflare'), 'qdrant' => __('Qdrant', 'aipcf-ai-provider-for-cloudflare'), 'pgvector' => __('PostgreSQL (pgvector)', 'aipcf-ai-provider-for-cloudflare'), ]; } /** * The store chosen in the settings. * * @return VectorStore|\WP_Error */ public static function current() { return self::make(self::currentId()); } /** * The store that searches, related posts and the link assistant read from. While a move * to another store is under way, that is the store being moved from; while a rebuild * fills a new index, it is the previous index, as long as its vectors come from the * current model. Only the embedding worker and the move write to the current store. * * @return VectorStore|\WP_Error */ public static function reading() { $state = \WordPress\CloudflareWorkersAiProvider\Embeddings\State::get(); $move = $state['move']; if ($move !== null && ($move['serve'] ?? 'from') === 'from') { return self::make((string) $move['from'], (string) $move['from_index']); } if ($move === null && $state['previous_index'] !== '' && $state['previous_model'] !== '' && $state['previous_model'] === \WordPress\CloudflareWorkersAiProvider\Embeddings\Models::current()) { return self::make(self::currentId(), $state['previous_index']); } return self::current(); } public static function currentId(): string { $id = (string) (get_plugin_settings()['embed_store'] ?? self::DEFAULT); return $id !== '' ? $id : self::DEFAULT; } /** * Drops a named index of the current store type (best effort). */ public static function dropNamed(string $index): bool { $store = self::make(self::currentId(), $index); return !is_wp_error($store) && $store->dropIndex() === true; } /** * The store for the configured index, or for a named one (e.g. the index a rebuild replaces). * * @return VectorStore|\WP_Error */ public static function make(string $id, ?string $index = null) { /** * Short-circuits store construction, e.g. to supply a custom backend. * * @param VectorStore|null $store Return a VectorStore to use it. * @param string $id The configured store id. * @param string|null $index A specific index name, or null for the configured one. */ $custom = apply_filters('aipcf_vector_store', null, $id, $index); if ($custom instanceof VectorStore) { return $custom; } if ($id === 'vectorize') { return new VectorizeStore($index); } if ($id === 'qdrant') { return new QdrantStore($index); } if ($id === 'pgvector') { return new PgvectorStore($index); } return new \WP_Error('aipcf_store_failed', __('Choose a vector store on Settings > Content index.', 'aipcf-ai-provider-for-cloudflare'), ['store' => $id]); } }