specified length of time. We'll use 7 days for simplicity, but you can pick whatever value make sense for your use case -- for example if you query recent vectors frequently you might want to use a smaller time delta like 1 day, or if you query vectors over a decade long time period then you might want to use a larger time delta like 6 months or 1 year.Finally, we'll create the TimescaleVector instance. We specify the ids argument to be the uuid field in our metadata that we created in the pre-processing step above. We do this because we want the time part of our uuids to reflect dates in the past (i.e when the commit was made). However, if we wanted the current date and time to be associated with our document, we can remove the id argument and uuid's will be automatically created with the current date and time.# Define collection nameCOLLECTION_NAME = "timescale_commits"embeddings = OpenAIEmbeddings()# Create a Timescale Vector instance from the collection of documentsdb = TimescaleVector.from_documents(      embedding=embeddings,      ids = [doc.metadata["id"] for doc in docs],      documents=docs,      collection_name=COLLECTION_NAME,      service_url=SERVICE_URL,      time_partition_interval=timedelta(days = 7),)Querying vectors by time and similarity‚ÄãNow that we have loaded our documents into TimescaleVector, we can query them by time and similarity.TimescaleVector provides multiple methods for querying vectors by doing similarity search with time-based filtering.Let's take a look at each method below:# Time filter variablesstart_dt = datetime(2023, 8, 1, 22, 10, 35) # Start date = 1 August 2023, 22:10:35end_dt = datetime(2023, 8, 30, 22, 10, 35) # End date = 30 August 2023, 22:10:35td = timedelta(days=7) # Time delta = 7 daysquery = "What's new with TimescaleDB functions?"Method 1: Filter within a provided start date and end date.# Method 1: Query for vectors between start_date and end_datedocs_with_score = db.similarity_search_with_score(query,
This notebook shows how to use the Postgres vector database Timescale Vector. You'll learn how to use TimescaleVector for (1) semantic search, (2) time-based vector search, (3) self-querying, and (4) how to create indexes to speed up queries.
This notebook shows how to use the Postgres vector database Timescale Vector. You'll learn how to use TimescaleVector for (1) semantic search, (2) time-based vector search, (3) self-querying, and (4) how to create indexes to speed up queries. ->: specified length of time. We'll use 7 days for simplicity, but you can pick whatever value make sense for your use case -- for example if you query recent vectors frequently you might want to use a smaller time delta like 1 day, or if you query vectors over a decade long time period then you might want to use a larger time delta like 6 months or 1 year.Finally, we'll create the TimescaleVector instance. We specify the ids argument to be the uuid field in our metadata that we created in the pre-processing step above. We do this because we want the time part of our uuids to reflect dates in the past (i.e when the commit was made). However, if we wanted the current date and time to be associated with our document, we can remove the id argument and uuid's will be automatically created with the current date and time.# Define collection nameCOLLECTION_NAME = "timescale_commits"embeddings = OpenAIEmbeddings()# Create a Timescale Vector instance from the collection of documentsdb = TimescaleVector.from_documents(      embedding=embeddings,      ids = [doc.metadata["id"] for doc in docs],      documents=docs,      collection_name=COLLECTION_NAME,      service_url=SERVICE_URL,      time_partition_interval=timedelta(days = 7),)Querying vectors by time and similarity‚ÄãNow that we have loaded our documents into TimescaleVector, we can query them by time and similarity.TimescaleVector provides multiple methods for querying vectors by doing similarity search with time-based filtering.Let's take a look at each method below:# Time filter variablesstart_dt = datetime(2023, 8, 1, 22, 10, 35) # Start date = 1 August 2023, 22:10:35end_dt = datetime(2023, 8, 30, 22, 10, 35) # End date = 30 August 2023, 22:10:35td = timedelta(days=7) # Time delta = 7 daysquery = "What's new with TimescaleDB functions?"Method 1: Filter within a provided start date and end date.# Method 1: Query for vectors between start_date and end_datedocs_with_score = db.similarity_search_with_score(query,