feat(clients): retrieval: Voyage, Jina, Pinecone, Qdrant, Weaviate, Mixedbread, Tavily, Exa, Brave
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// Route: POST /ai/retrieval/call (generic table-driven call: 422, dry runs, 503 without a credential)
|
||||
#include <cstdlib>
|
||||
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("MOLO_ENV_FILES", "off", 1);
|
||||
for (const char* v : {"VOYAGE_API_KEY", "JINA_API_KEY", "PINECONE_API_KEY", "QDRANT_API_KEY", "QDRANT_URL", "WEAVIATE_API_KEY",
|
||||
"WEAVIATE_URL", "MXBAI_API_KEY", "TAVILY_API_KEY", "EXA_API_KEY", "BRAVE_API_KEY"})
|
||||
unsetenv(v);
|
||||
Fixture f;
|
||||
auto post = [&](const std::string& body) { return f.client->post("/ai/retrieval/call", body, "application/json"); };
|
||||
|
||||
// 422: input rules run before anything else
|
||||
check(post("{\"provider\":\"qdrant\"}").status == 422, "call name is required");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"nope\"}").status == 422, "unknown call");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collection\"}").status == 422, "missing path parameter");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collection\",\"path\":{\"collection_name\":\"../x\"}}").status == 422, "path traversal id");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collection\",\"path\":{\"collection_name\":\"a b\"}}").status == 422, "id with a space");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collections\",\"query\":{\"bogus\":1}}").status == 422, "query parameter not in the table");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collections\",\"body\":{\"a\":1}}").status == 422, "GET takes no body");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"upsert_points\",\"path\":{\"collection_name\":\"c\"},\"body\":{\"nope\":1}}").status == 422, "body field not in the table");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collections\",\"path\":[1]}").status == 422, "path must be an object");
|
||||
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collections\",\"query\":{\"x\":[1]}}").status == 422, "query values are scalars");
|
||||
check(post("{\"provider\":\"pinecone\",\"call\":\"describe_index_stats\",\"body\":{}}").status == 422, "data plane call needs index_host");
|
||||
check(post("{\"provider\":\"pinecone\",\"call\":\"describe_index_stats\",\"index_host\":\"https://x.io\",\"body\":{}}").status == 422, "index_host must be a bare host");
|
||||
|
||||
// dry runs: writes, destructive and paid calls show the exact request
|
||||
auto upsert = post("{\"provider\":\"qdrant\",\"call\":\"upsert_points\",\"path\":{\"collection_name\":\"docs\"},\"query\":{\"wait\":true},\"body\":{\"points\":[]}}");
|
||||
check(upsert.status == 200 && contains(upsert.body, "\"dry_run\":true") && contains(upsert.body, "/collections/docs/points?wait=true"),
|
||||
"upsert is a dry run with the rendered target");
|
||||
auto del = post("{\"provider\":\"qdrant\",\"call\":\"delete_collection\",\"path\":{\"collection_name\":\"docs\"}}");
|
||||
check(del.status == 200 && contains(del.body, "\"dry_run\":true") && contains(del.body, "\"flags\":\"d\""), "delete collection is a dry run");
|
||||
auto delidx = post("{\"provider\":\"pinecone\",\"call\":\"delete_index\",\"path\":{\"index_name\":\"docs\"}}");
|
||||
check(delidx.status == 200 && contains(delidx.body, "\"dry_run\":true"), "delete index is a dry run");
|
||||
auto delvec = post("{\"provider\":\"pinecone\",\"call\":\"delete_vectors\",\"index_host\":\"docs-abc.svc.pinecone.io\",\"body\":{\"deleteAll\":true}}");
|
||||
check(delvec.status == 200 && contains(delvec.body, "\"dry_run\":true") && contains(delvec.body, "deleteAll"), "delete vectors is a dry run");
|
||||
auto paid = post("{\"provider\":\"voyage\",\"call\":\"embed\",\"body\":{\"input\":[\"a\"],\"model\":\"voyage-3.5\"}}");
|
||||
check(paid.status == 200 && contains(paid.body, "\"dry_run\":true") && contains(paid.body, "/v1/embeddings"), "paid call is a dry run");
|
||||
|
||||
// 503: free reads and confirmed calls need the credential
|
||||
for (const char* body : {"{\"provider\":\"qdrant\",\"call\":\"get_collections\"}",
|
||||
"{\"provider\":\"weaviate\",\"call\":\"schema_dump\"}",
|
||||
"{\"provider\":\"pinecone\",\"call\":\"list_indexes\"}",
|
||||
"{\"provider\":\"mixedbread\",\"call\":\"list_stores\"}",
|
||||
"{\"provider\":\"jina\",\"call\":\"list_models\"}",
|
||||
"{\"provider\":\"tavily\",\"call\":\"get_usage\"}",
|
||||
"{\"provider\":\"pinecone\",\"call\":\"describe_index_stats\",\"index_host\":\"docs-abc.svc.pinecone.io\",\"body\":{}}",
|
||||
"{\"provider\":\"qdrant\",\"call\":\"delete_collection\",\"path\":{\"collection_name\":\"docs\"},\"confirm\":true}",
|
||||
"{\"provider\":\"pinecone\",\"call\":\"delete_index\",\"path\":{\"index_name\":\"docs\"},\"confirm\":true}",
|
||||
"{\"provider\":\"voyage\",\"call\":\"rerank\",\"body\":{\"query\":\"q\",\"documents\":[\"a\"],\"model\":\"rerank-2.5\"},\"confirm\":true}"}) {
|
||||
auto res = post(body);
|
||||
check(res.status == 503 && contains(res.body, "retrieval_not_configured"), std::string("503 without a credential: ") + body);
|
||||
}
|
||||
return finish("ai/retrieval/call");
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Routes: GET /ai/retrieval (page), /status, /calls (no credential needed)
|
||||
#include <cstdlib>
|
||||
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("MOLO_ENV_FILES", "off", 1);
|
||||
for (const char* v : {"VOYAGE_API_KEY", "JINA_API_KEY", "PINECONE_API_KEY", "QDRANT_API_KEY", "QDRANT_URL", "WEAVIATE_API_KEY",
|
||||
"WEAVIATE_URL", "MXBAI_API_KEY", "TAVILY_API_KEY", "EXA_API_KEY", "BRAVE_API_KEY"})
|
||||
unsetenv(v);
|
||||
Fixture f;
|
||||
auto page = f.client->get("/ai/retrieval");
|
||||
check(page.status == 200, "page 200");
|
||||
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
|
||||
check(contains(page.body, "Retrieval vendors") && contains(page.body, "viewport"), "title and mobile viewport");
|
||||
check(contains(page.body, "/embedded/ai_retrieval.js"), "script wired");
|
||||
check(f.client->post("/ai/retrieval", "{}", "application/json").status == 405, "post page is 405");
|
||||
|
||||
auto st = f.client->get("/ai/retrieval/status");
|
||||
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without a key");
|
||||
check(!contains(st.body, "\"configured\":true"), "no provider claims a credential");
|
||||
for (const char* env : {"VOYAGE_API_KEY", "JINA_API_KEY", "PINECONE_API_KEY", "QDRANT_API_KEY", "QDRANT_URL", "WEAVIATE_API_KEY",
|
||||
"WEAVIATE_URL", "MXBAI_API_KEY", "TAVILY_API_KEY", "EXA_API_KEY", "BRAVE_API_KEY"})
|
||||
check(contains(st.body, env), std::string("status names ") + env);
|
||||
for (const char* id : {"voyage", "jina", "pinecone", "qdrant", "weaviate", "mixedbread", "tavily", "exa", "brave"})
|
||||
check(contains(st.body, std::string("\"id\":\"") + id + "\""), std::string("status lists ") + id);
|
||||
check(contains(st.body, "\"max_embed_texts\":1000"), "caps listed");
|
||||
check(f.client->post("/ai/retrieval/status", "{}", "application/json").status == 405, "post status is 405");
|
||||
|
||||
auto calls = f.client->get("/ai/retrieval/calls");
|
||||
check(calls.status == 200 && contains(calls.body, "/collections/{collection_name}/points/query") &&
|
||||
contains(calls.body, "/v1/web/search") && contains(calls.body, "/v1/embeddings") && contains(calls.body, "/vectors/upsert"),
|
||||
"all call tables listed");
|
||||
check(contains(calls.body, "\"unverified\":true"), "unverified rows are marked");
|
||||
auto one = f.client->get("/ai/retrieval/calls?provider=pinecone");
|
||||
check(one.status == 200 && contains(one.body, "\"count\":57") && !contains(one.body, "\"provider\":\"qdrant\""), "filter by provider");
|
||||
check(f.client->get("/ai/retrieval/calls?provider=nope").status == 422, "unknown provider filter is 422");
|
||||
return finish("ai/retrieval/page");
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Routes: POST /ai/retrieval/{embed,rerank,search} (405, 422, dry runs, 503 without a credential)
|
||||
#include <cstdlib>
|
||||
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("MOLO_ENV_FILES", "off", 1);
|
||||
for (const char* v : {"VOYAGE_API_KEY", "JINA_API_KEY", "PINECONE_API_KEY", "MXBAI_API_KEY", "TAVILY_API_KEY", "EXA_API_KEY", "BRAVE_API_KEY"})
|
||||
unsetenv(v);
|
||||
Fixture f;
|
||||
auto post = [&](const std::string& route, const std::string& body) {
|
||||
return f.client->post("/ai/retrieval/" + route, body, "application/json");
|
||||
};
|
||||
for (const char* r : {"embed", "rerank", "search", "call"}) {
|
||||
std::string route = std::string("/ai/retrieval/") + r;
|
||||
check(f.client->get(route).status == 405, route + " get is 405");
|
||||
check(post(r, "not json").status == 422, route + " bad json is 422");
|
||||
check(post(r, "[1]").status == 422, route + " non-object is 422");
|
||||
check(post(r, "{}").status == 422, route + " needs a provider");
|
||||
check(post(r, "{\"provider\":\"nope\"}").status == 422, route + " unknown provider is 422");
|
||||
}
|
||||
|
||||
// embed
|
||||
check(post("embed", "{\"provider\":\"voyage\"}").status == 422, "embed needs texts");
|
||||
check(post("embed", "{\"provider\":\"voyage\",\"texts\":[]}").status == 422, "embed empty texts");
|
||||
check(post("embed", "{\"provider\":\"voyage\",\"texts\":[\" \"]}").status == 422, "embed blank text");
|
||||
check(post("embed", "{\"provider\":\"voyage\",\"texts\":[1]}").status == 422, "embed texts must be strings");
|
||||
check(post("embed", "{\"provider\":\"voyage\",\"texts\":[\"a\"],\"input_type\":\"other\"}").status == 422, "embed bad input_type");
|
||||
check(post("embed", "{\"provider\":\"voyage\",\"texts\":[\"a\"],\"dimensions\":99999}").status == 422, "embed dimensions cap");
|
||||
check(post("embed", "{\"provider\":\"tavily\",\"texts\":[\"a\"]}").status == 422, "tavily has no embeddings");
|
||||
check(post("embed", "{\"provider\":\"qdrant\",\"texts\":[\"a\"]}").status == 422, "qdrant has no embeddings");
|
||||
auto dry = post("embed", "{\"provider\":\"voyage\",\"texts\":[\"a\",\"b\"],\"input_type\":\"query\"}");
|
||||
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true") && contains(dry.body, "\"texts\":2"), "embed is a dry run without confirm");
|
||||
for (const char* p : {"voyage", "jina", "pinecone", "mixedbread"}) {
|
||||
auto res = post("embed", std::string("{\"provider\":\"") + p + "\",\"texts\":[\"a\"],\"confirm\":true}");
|
||||
check(res.status == 503 && contains(res.body, "retrieval_not_configured"), std::string("confirmed embed without key is 503: ") + p);
|
||||
}
|
||||
|
||||
// rerank
|
||||
check(post("rerank", "{\"provider\":\"jina\",\"query\":\"q\"}").status == 422, "rerank needs documents");
|
||||
check(post("rerank", "{\"provider\":\"jina\",\"query\":\" \",\"documents\":[\"a\"]}").status == 422, "rerank blank query");
|
||||
check(post("rerank", "{\"provider\":\"jina\",\"query\":\"q\",\"documents\":[\"a\"],\"top_n\":-1}").status == 422, "rerank negative top_n");
|
||||
check(post("rerank", "{\"provider\":\"tavily\",\"query\":\"q\",\"documents\":[\"a\"]}").status == 422, "tavily has no rerank");
|
||||
check(contains(post("rerank", "{\"provider\":\"jina\",\"query\":\"q\",\"documents\":[\"a\",\"b\"]}").body, "\"dry_run\":true"), "rerank is a dry run");
|
||||
for (const char* p : {"voyage", "jina", "pinecone", "mixedbread"}) {
|
||||
auto res = post("rerank", std::string("{\"provider\":\"") + p + "\",\"query\":\"q\",\"documents\":[\"a\"],\"confirm\":true}");
|
||||
check(res.status == 503 && contains(res.body, "retrieval_not_configured"), std::string("confirmed rerank without key is 503: ") + p);
|
||||
}
|
||||
|
||||
// search
|
||||
check(post("search", "{\"provider\":\"tavily\"}").status == 422, "search needs a query");
|
||||
check(post("search", "{\"provider\":\"tavily\",\"query\":\"x\",\"max_results\":0}").status == 422, "search max_results 0");
|
||||
check(post("search", "{\"provider\":\"tavily\",\"query\":\"x\",\"max_results\":101}").status == 422, "search max_results over cap");
|
||||
check(post("search", "{\"provider\":\"tavily\",\"query\":\"x\",\"recency\":\"decade\"}").status == 422, "search bad recency");
|
||||
check(post("search", "{\"provider\":\"voyage\",\"query\":\"x\"}").status == 422, "voyage has no web search");
|
||||
check(post("search", "{\"provider\":\"pinecone\",\"query\":\"x\"}").status == 422, "pinecone has no web search");
|
||||
check(contains(post("search", "{\"provider\":\"brave\",\"query\":\"x\"}").body, "\"dry_run\":true"), "search is a dry run");
|
||||
for (const char* p : {"jina", "tavily", "exa", "brave"}) {
|
||||
auto res = post("search", std::string("{\"provider\":\"") + p + "\",\"query\":\"x\",\"confirm\":true}");
|
||||
check(res.status == 503 && contains(res.body, "retrieval_not_configured"), std::string("confirmed search without key is 503: ") + p);
|
||||
}
|
||||
// adapter rules that only show on a confirmed call
|
||||
check(post("search", "{\"provider\":\"jina\",\"query\":\"x\",\"recency\":\"day\",\"confirm\":true}").status == 422, "jina has no recency filter");
|
||||
check(post("search", "{\"provider\":\"brave\",\"query\":\"x\",\"max_results\":21,\"confirm\":true}").status == 422, "brave web search is capped at 20");
|
||||
check(post("search", "{\"provider\":\"tavily\",\"query\":\"x\",\"max_results\":21,\"confirm\":true}").status == 422, "tavily search is capped at 20");
|
||||
return finish("ai/retrieval/routes");
|
||||
}
|
||||
Reference in New Issue
Block a user