Skip to content

Commit

Permalink
added tests for index metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
swetavooda committed Apr 24, 2024
1 parent ef3fb32 commit 578dc3b
Show file tree
Hide file tree
Showing 2 changed files with 451 additions and 0 deletions.
257 changes: 257 additions & 0 deletions test/expected/pinecone_index_metrics.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
-- SETUP
-- suppress output
\o /dev/null
--starting
delete from pinecone_mock;
-- logging level
SET client_min_messages = 'notice';
-- disable flat scan to force use of the index
SET enable_seqscan = true;
-- CREATE TABLE
DROP TABLE IF EXISTS t;
NOTICE: table "t" does not exist, skipping
CREATE TABLE t (id int, val vector(2));
\o
-- CREATE INDEX
-- mock create index
INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://api.pinecone.io/indexes', 'POST', $${
"name": "invalid",
"metric": "euclidean",
"dimension": 3,
"status": {
"ready": true,
"state": "Ready"
},
"host": "fakehost",
"spec": {
"serverless": {
"cloud": "aws",
"region": "us-west-2"
}
}
}$$);
INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://api.pinecone.io/indexes', 'POST', $${
"name": "invalid",
"metric": "cosine",
"dimension": 3,
"status": {
"ready": true,
"state": "Ready"
},
"host": "fakehost",
"spec": {
"serverless": {
"cloud": "aws",
"region": "us-west-2"
}
}
}$$);
INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://api.pinecone.io/indexes', 'POST', $${
"name": "invalid",
"metric": "inner",
"dimension": 3,
"status": {
"ready": true,
"state": "Ready"
},
"host": "fakehost",
"spec": {
"serverless": {
"cloud": "aws",
"region": "us-west-2"
}
}
}$$);
-- mock describe index stats
INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://fakehost/describe_index_stats', 'GET', '{"namespaces":{},"dimension":2,"indexFullness":0,"totalVectorCount":0}');
-- mock fetch
INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://fakehost/vectors/fetch', 'GET', $${
"code": 3,
"message": "No IDs provided for fetch query",
"details": []
}$$);
INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://fakehost/vectors/upsert',
'{ "vectors": [{
"id": "000000000001",
"values": [1, 1],
"metadata": {
}
}, {
"id": "000000000002",
"values": [3, 0],
"metadata": {
}
}, {
"id": "000000000003",
"values": [4, 1],
"metadata": {
}
}]
}');
ERROR: INSERT has more target columns than expressions
LINE 1: INSERT INTO pinecone_mock (url_prefix, method, response)
^
INSERT INTO t (id, val) VALUES (1, '[1,1]');
INSERT INTO t (id, val) VALUES (2, '[3,0]');
INSERT INTO t (id, val) VALUES (3, '[4,1]');
CREATE INDEX i1 ON t USING pinecone (val vector_l2_ops) WITH (spec = '{"serverless":{"cloud":"aws","region":"us-west-2"}}');
ERROR: No matching mock response found for query: SELECT response, curl_code FROM pinecone_mock WHERE ('https://fakehost/vectors/upsert' LIKE url_prefix || '%' OR url_prefix IS NULL) AND (method IS NULL OR method = 'POST') AND (body IS NULL OR body = '{
"vectors": [{
"id": "000000000001",
"values": [1, 1],
"metadata": {
}
}, {
"id": "000000000002",
"values": [3, 0],
"metadata": {
}
}, {
"id": "000000000003",
"values": [4, 1],
"metadata": {
}
}]
}');
CREATE INDEX i2 ON t USING pinecone (val vector_cosine_ops) WITH (spec = '{"serverless":{"cloud":"aws","region":"us-west-2"}}');
ERROR: No matching mock response found for query: SELECT response, curl_code FROM pinecone_mock WHERE ('https://fakehost/vectors/upsert' LIKE url_prefix || '%' OR url_prefix IS NULL) AND (method IS NULL OR method = 'POST') AND (body IS NULL OR body = '{
"vectors": [{
"id": "000000000001",
"values": [1, 1],
"metadata": {
}
}, {
"id": "000000000002",
"values": [3, 0],
"metadata": {
}
}, {
"id": "000000000003",
"values": [4, 1],
"metadata": {
}
}]
}');
CREATE INDEX i3 ON t USING pinecone (val vector_ip_ops) WITH (spec = '{"serverless":{"cloud":"aws","region":"us-west-2"}}');
ERROR: No matching mock response found for query: SELECT response, curl_code FROM pinecone_mock WHERE ('https://fakehost/vectors/upsert' LIKE url_prefix || '%' OR url_prefix IS NULL) AND (method IS NULL OR method = 'POST') AND (body IS NULL OR body = '{
"vectors": [{
"id": "000000000001",
"values": [1, 1],
"metadata": {
}
}, {
"id": "000000000002",
"values": [3, 0],
"metadata": {
}
}, {
"id": "000000000003",
"values": [4, 1],
"metadata": {
}
}]
}');
INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://fakehost/query', 'POST', $${
"results": [],
"matches": [{
"id": "000000000001",
"score": 1,
"values": []
}, {
"id": "000000000002",
"score": 4,
"values": []
}, {
"id": "000000000003",
"score": 10,
"values": []
}],
"namespace": "",
"usage": {
"readUnits": 5
}
}

$$);
SELECT id,val,val<->'[1,0]' as dist FROM t ORDER BY val <-> '[1,0]';
id | val | dist
----+-------+--------------------
1 | [1,1] | 1
2 | [3,0] | 2
3 | [4,1] | 3.1622776601683795
(3 rows)

DELETE FROM pinecone_mock
WHERE url_prefix = 'https://fakehost/query' AND method = 'POST';
INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://fakehost/query', 'POST', $${
"results": [],
"matches": [{
"id": "000000000003",
"score": 4,
"values": []
}, {
"id": "000000000002",
"score": 3,
"values": []
}, {
"id": "000000000001",
"score": 1,
"values": []
}],
"namespace": "",
"usage": {
"readUnits": 5
}
}

$$);
SELECT id,val,val<=>'[1,0]' as dist FROM t ORDER BY val <=> '[1,0]';
id | val | dist
----+-------+----------------------
2 | [3,0] | 0
3 | [4,1] | 0.029857499854668124
1 | [1,1] | 0.29289321881345254
(3 rows)

DELETE FROM pinecone_mock
WHERE url_prefix = 'https://fakehost/query' AND method = 'POST';
SELECT id,val,val<#>'[1,0]' as dist FROM t ORDER BY val <#> '[1,0]';
id | val | dist
----+-------+------
3 | [4,1] | -4
2 | [3,0] | -3
1 | [1,1] | -1
(3 rows)

INSERT INTO pinecone_mock (url_prefix, method, response)
VALUES ('https://fakehost/query', 'POST', $${
"results": [],
"matches": [{
"id": "000000000003",
"score": 4,
"values": []
}, {
"id": "000000000002",
"score": 3,
"values": []
}, {
"id": "000000000001",
"score": 1,
"values": []
}],
"namespace": "",
"usage": {
"readUnits": 5
}
}

$$);
DROP TABLE t;
Loading

0 comments on commit 578dc3b

Please sign in to comment.