Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for metadata values of type array #18

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Timescale Vector


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

PostgreSQL++ for AI Applications.
Expand Down Expand Up @@ -109,12 +110,12 @@ Now, you can query for similar items:
vec.search([1.0, 9.0])
```

[[UUID('73d05df0-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('45ecb666-0f15-11ef-8d89-e666703872d0'),
{'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
0.00016793422934946456],
[UUID('73d05d6e-84c1-11ee-98da-6ee10b77fd08'),
[UUID('45ecb350-0f15-11ef-8d89-e666703872d0'),
{'animal': 'fox'},
'the brown fox',
array([1. , 1.3], dtype=float32),
Expand All @@ -130,7 +131,7 @@ constrained by a metadata filter.
vec.search([1.0, 9.0], limit=1, filter={"action": "jump"})
```

[[UUID('73d05df0-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('45ecb666-0f15-11ef-8d89-e666703872d0'),
{'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand All @@ -154,7 +155,7 @@ records = vec.search([1.0, 9.0], limit=1, filter={"action": "jump"})
(records[0]["id"],records[0]["metadata"], records[0]["contents"], records[0]["embedding"], records[0]["distance"])
```

(UUID('73d05df0-84c1-11ee-98da-6ee10b77fd08'),
(UUID('45ecb666-0f15-11ef-8d89-e666703872d0'),
{'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand Down Expand Up @@ -217,12 +218,12 @@ The basic query looks like:
vec.search([1.0, 9.0])
```

[[UUID('7487af96-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629b54-0f15-11ef-8d89-e666703872d0'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
0.00016793422934946456],
[UUID('7487af14-84c1-11ee-98da-6ee10b77fd08'),
[UUID('4d629a50-0f15-11ef-8d89-e666703872d0'),
{'times': 1, 'action': 'sit', 'animal': 'fox'},
'the brown fox',
array([1. , 1.3], dtype=float32),
Expand All @@ -234,7 +235,7 @@ You could provide a limit for the number of items returned:
vec.search([1.0, 9.0], limit=1)
```

[[UUID('7487af96-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629b54-0f15-11ef-8d89-e666703872d0'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand All @@ -259,7 +260,7 @@ unconstrained):
vec.search([1.0, 9.0], limit=1, filter={"action": "sit"})
```

[[UUID('7487af14-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629a50-0f15-11ef-8d89-e666703872d0'),
{'times': 1, 'action': 'sit', 'animal': 'fox'},
'the brown fox',
array([1. , 1.3], dtype=float32),
Expand All @@ -272,12 +273,12 @@ returned if it matches any dict:
vec.search([1.0, 9.0], limit=2, filter=[{"action": "jump"}, {"animal": "fox"}])
```

[[UUID('7487af96-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629b54-0f15-11ef-8d89-e666703872d0'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
0.00016793422934946456],
[UUID('7487af14-84c1-11ee-98da-6ee10b77fd08'),
[UUID('4d629a50-0f15-11ef-8d89-e666703872d0'),
{'times': 1, 'action': 'sit', 'animal': 'fox'},
'the brown fox',
array([1. , 1.3], dtype=float32),
Expand All @@ -292,7 +293,7 @@ could use greater than and less than conditions on numeric values.
vec.search([1.0, 9.0], limit=2, predicates=client.Predicates("times", ">", 1))
```

[[UUID('7487af96-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629b54-0f15-11ef-8d89-e666703872d0'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand All @@ -316,7 +317,7 @@ use the right type. Supported Python types are: `str`, `int`, and
vec.search([1.0, 9.0], limit=2, predicates=client.Predicates("action", "==", "jump"))
```

[[UUID('7487af96-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629b54-0f15-11ef-8d89-e666703872d0'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand All @@ -330,7 +331,7 @@ combining using OR semantic). So you can do:
vec.search([1.0, 9.0], limit=2, predicates=client.Predicates("action", "==", "jump") & client.Predicates("times", ">", 1))
```

[[UUID('7487af96-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629b54-0f15-11ef-8d89-e666703872d0'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand All @@ -353,7 +354,7 @@ my_predicates = client.Predicates("action", "==", "jump") & (client.Predicates("
vec.search([1.0, 9.0], limit=2, predicates=my_predicates)
```

[[UUID('7487af96-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629b54-0f15-11ef-8d89-e666703872d0'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand All @@ -367,7 +368,7 @@ semantics. You can pass in multiple 3-tuples to
vec.search([1.0, 9.0], limit=2, predicates=client.Predicates(("action", "==", "jump"), ("times", ">", 10)))
```

[[UUID('7487af96-84c1-11ee-98da-6ee10b77fd08'),
[[UUID('4d629b54-0f15-11ef-8d89-e666703872d0'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand Down Expand Up @@ -399,7 +400,7 @@ Then, you can filter using the timestamps by specifing a
tpvec.search([1.0, 9.0], limit=4, uuid_time_filter=client.UUIDTimeRange(specific_datetime, specific_datetime+timedelta(days=1)))
```

[[UUID('33c52800-ef15-11e7-be03-4f1f9a1bde5a'),
[[UUID('95899000-ef1d-11e7-990e-7d2f7e013038'),
{'times': 1, 'action': 'sit', 'animal': 'fox'},
'the brown fox',
array([1. , 1.3], dtype=float32),
Expand All @@ -415,12 +416,12 @@ unconstrained.
tpvec.search([1.0, 9.0], limit=4, uuid_time_filter=client.UUIDTimeRange(start_date=specific_datetime))
```

[[UUID('ac8be800-0de6-11e9-889a-5eec84ba8a7b'),
[[UUID('0e505000-0def-11e9-8732-a154fea6fb50'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
0.00016793422934946456],
[UUID('33c52800-ef15-11e7-be03-4f1f9a1bde5a'),
[UUID('95899000-ef1d-11e7-990e-7d2f7e013038'),
{'times': 1, 'action': 'sit', 'animal': 'fox'},
'the brown fox',
array([1. , 1.3], dtype=float32),
Expand All @@ -437,7 +438,7 @@ One example:
tpvec.search([1.0, 9.0], limit=4, uuid_time_filter=client.UUIDTimeRange(start_date=specific_datetime, start_inclusive=False))
```

[[UUID('ac8be800-0de6-11e9-889a-5eec84ba8a7b'),
[[UUID('0e505000-0def-11e9-8732-a154fea6fb50'),
{'times': 100, 'action': 'jump', 'animal': 'fox'},
'jumped over the',
array([ 1. , 10.8], dtype=float32),
Expand All @@ -459,7 +460,7 @@ filters and `__uuid_timestamp` for predicates. Some examples below:
tpvec.search([1.0, 9.0], limit=4, filter={ "__start_date": specific_datetime, "__end_date": specific_datetime+timedelta(days=1)})
```

[[UUID('33c52800-ef15-11e7-be03-4f1f9a1bde5a'),
[[UUID('95899000-ef1d-11e7-990e-7d2f7e013038'),
{'times': 1, 'action': 'sit', 'animal': 'fox'},
'the brown fox',
array([1. , 1.3], dtype=float32),
Expand All @@ -470,7 +471,7 @@ tpvec.search([1.0, 9.0], limit=4,
predicates=client.Predicates("__uuid_timestamp", ">", specific_datetime) & client.Predicates("__uuid_timestamp", "<", specific_datetime+timedelta(days=1)))
```

[[UUID('33c52800-ef15-11e7-be03-4f1f9a1bde5a'),
[[UUID('95899000-ef1d-11e7-990e-7d2f7e013038'),
{'times': 1, 'action': 'sit', 'animal': 'fox'},
'the brown fox',
array([1. , 1.3], dtype=float32),
Expand Down Expand Up @@ -839,7 +840,7 @@ import psycopg2
from langchain.docstore.document import Document
from langchain.text_splitter import CharacterTextSplitter
from timescale_vector import client, pgvectorizer
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain_openai import OpenAIEmbeddings
from langchain.vectorstores.timescalevector import TimescaleVector
from datetime import timedelta
```
Expand Down Expand Up @@ -952,8 +953,8 @@ res = vector_store.similarity_search_with_score("Blogs about cats")
res
```

[(Document(page_content='Author Matvey Arye, title: First Post, contents:some super interesting content about cats.', metadata={'id': '4a784000-4bc4-11eb-855a-06302dbc8ce7', 'author': 'Matvey Arye', 'blog_id': 1, 'category': 'AI', 'published_time': '2021-01-01T00:00:00+00:00'}),
0.12595687795193833)]
[(Document(page_content='Author Matvey Arye, title: First Post, contents:some super interesting content about cats.', metadata={'id': '4a784000-4bc4-11eb-979c-e8748f6439f2', 'author': 'Matvey Arye', 'blog_id': 1, 'category': 'AI', 'published_time': '2021-01-01T00:00:00+00:00'}),
0.12657619616729976)]

## Development

Expand Down
Loading