mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 07:49:01 +00:00
The provider-agnostic vector store stack (VectorStore::Pgvector + the Embeddable concern) already shipped to main. This PR closes the Anthropic loop: - VectorStore::Registry.adapter_name now returns :pgvector when Setting.llm_provider == "anthropic" and no explicit VECTOR_STORE_PROVIDER override is set. Anthropic has no hosted vector store, so falling back to the local pgvector adapter is the only correct default. Explicit VECTOR_STORE_PROVIDER still wins. - SearchFamilyFiles surfaces a longer message when no adapter is wired up — calling out pgvector + EMBEDDING_URI_BASE as the supported Anthropic-only path so the user is not stuck with an "OpenAI required" hint that is no longer accurate. The Embeddable concern already pulls embeddings from EMBEDDING_URI_BASE / EMBEDDING_ACCESS_TOKEN (with OpenAI as fallback), so Anthropic installs point this at Voyage AI, a local Ollama instance, or OpenAI embeddings — independent of the chat provider. Tests cover the new default routing, the existing OpenAI default staying intact, and explicit VECTOR_STORE_PROVIDER overriding the Anthropic default. Stacked on #1985 (PR 3/5). 5/5 settings UI + retention disclosure next.
84 lines
3.1 KiB
Ruby
84 lines
3.1 KiB
Ruby
require "test_helper"
|
|
|
|
class VectorStore::RegistryTest < ActiveSupport::TestCase
|
|
test "adapter_name defaults to openai when access token present" do
|
|
VectorStore::Registry.stubs(:openai_access_token).returns("sk-test")
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: nil) do
|
|
assert_equal :openai, VectorStore::Registry.adapter_name
|
|
end
|
|
end
|
|
|
|
test "adapter_name returns nil when no credentials configured" do
|
|
VectorStore::Registry.stubs(:openai_access_token).returns(nil)
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: nil) do
|
|
assert_nil VectorStore::Registry.adapter_name
|
|
end
|
|
end
|
|
|
|
test "adapter_name respects explicit VECTOR_STORE_PROVIDER" do
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: "qdrant") do
|
|
assert_equal :qdrant, VectorStore::Registry.adapter_name
|
|
end
|
|
end
|
|
|
|
test "adapter_name falls back to openai for unknown provider" do
|
|
VectorStore::Registry.stubs(:openai_access_token).returns("sk-test")
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: "unknown_store") do
|
|
assert_equal :openai, VectorStore::Registry.adapter_name
|
|
end
|
|
end
|
|
|
|
test "adapter returns VectorStore::Openai instance when openai configured" do
|
|
VectorStore::Registry.stubs(:openai_access_token).returns("sk-test")
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: nil) do
|
|
adapter = VectorStore::Registry.adapter
|
|
assert_instance_of VectorStore::Openai, adapter
|
|
end
|
|
end
|
|
|
|
test "adapter returns nil when nothing configured" do
|
|
VectorStore::Registry.stubs(:openai_access_token).returns(nil)
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: nil) do
|
|
assert_nil VectorStore::Registry.adapter
|
|
end
|
|
end
|
|
|
|
test "adapter returns VectorStore::Pgvector instance when pgvector configured" do
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: "pgvector") do
|
|
adapter = VectorStore::Registry.adapter
|
|
assert_instance_of VectorStore::Pgvector, adapter
|
|
end
|
|
end
|
|
|
|
test "adapter_name defaults to pgvector when LLM_PROVIDER is anthropic" do
|
|
Setting.stubs(:llm_provider).returns("anthropic")
|
|
VectorStore::Registry.stubs(:openai_access_token).returns(nil)
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: nil) do
|
|
assert_equal :pgvector, VectorStore::Registry.adapter_name
|
|
end
|
|
end
|
|
|
|
test "adapter_name routes anthropic installs to pgvector even when OpenAI key is present" do
|
|
Setting.stubs(:llm_provider).returns("anthropic")
|
|
VectorStore::Registry.stubs(:openai_access_token).returns("sk-test")
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: nil) do
|
|
assert_equal :pgvector, VectorStore::Registry.adapter_name
|
|
end
|
|
end
|
|
|
|
test "explicit VECTOR_STORE_PROVIDER overrides anthropic default" do
|
|
Setting.stubs(:llm_provider).returns("anthropic")
|
|
ClimateControl.modify(VECTOR_STORE_PROVIDER: "qdrant") do
|
|
assert_equal :qdrant, VectorStore::Registry.adapter_name
|
|
end
|
|
end
|
|
|
|
test "configured? delegates to adapter presence" do
|
|
VectorStore::Registry.stubs(:adapter).returns(nil)
|
|
assert_not VectorStore.configured?
|
|
|
|
VectorStore::Registry.stubs(:adapter).returns(VectorStore::Openai.new(access_token: "sk-test"))
|
|
assert VectorStore.configured?
|
|
end
|
|
end
|