# Time to live (TTL)

:::callout{intent="info" title="Added in `v1.36`"}
:::

Time-to-live (TTL) allows you to set an expiration time for objects in a collection.

Expired objects are periodically removed from the collection by Weaviate's background processes, helping you manage data lifecycle and storage.

TTLs are currently defined at the collection level. They can be set [relative to an object's creation time](#relative-to-a-creation-time), [the last update time](#relative-to-a-last-update-time), or [a specific `DATE` property](#relative-to-a-specific-date-property) within the object.

With all TTL definitions, you can optionally set whether to exclude expired, but not yet deleted, objects from query results. This can prevent erroneous data retrieval before the background deletion process runs.

:::callout{intent="info" title="Prerequisites"}
TTL requires the [`OBJECTS_TTL_DELETE_SCHEDULE`](../database-configuration/overview.md) environment variable to be set on the Weaviate instance. This variable defines the cron schedule for the background deletion process. If it is not set, expired objects will not be deleted.

The minimum TTL value is 60 seconds.
:::

## Relative to a creation time

Set a TTL to count forward from the object's creation time metadata. The value must be positive.

::::tabs{sync="languages"}
:::tab{title="Python"}
```python
from weaviate.classes.config import Configure, Property, DataType
import datetime

client.collections.create(
    name="CollectionWithTTL",
    properties=[
        Property(name="referenceDate", data_type=DataType.DATE),
    ],
    object_ttl_config=Configure.ObjectTTL.delete_by_creation_time(
        time_to_live=datetime.timedelta(hours=1),  # Or set 3600 for seconds
        filter_expired_objects=True,  # Optional: automatically filter out expired objects from queries
    ),
)
```
:::

:::tab{title="JavaScript/TypeScript"}
```typescript
await client.collections.create({
  name: 'CollectionWithTTL',
  properties: [
    { name: 'referenceDate', dataType: dataType.DATE },
  ],
  objectTTL: configure.objectTTL.deleteByCreationTime({
    defaultTTLSeconds: 3600,  // 1 hour
    filterExpiredObjects: true,  // Optional: automatically filter out expired objects from queries
  }),
});
```
:::

:::tab{title="Java"}
```java
client.collections.create("CollectionWithTTL",
    c -> c.properties(Property.date("referenceDate"))
        .objectTtl(ttl -> ttl
            .deleteByCreationTime()
            .defaultTtlSeconds(3600)  // 1 hour
            .filterExpiredObjects(true)  // Optional: automatically filter out expired objects from queries
        ));
```
:::

  <!-- <TabItem value="csharp" label="C#">
    <FilteredTextBlock
      text=
      startMarker="// START TTLByCreationTime"
      endMarker="// END TTLByCreationTime"
      language="csharp"
    />
  </TabItem> -->
::::

## Relative to a last update time

Set a TTL to count forward from the object's last updated time metadata. The value must be positive.

::::tabs{sync="languages"}
:::tab{title="Python"}
```python
from weaviate.classes.config import Configure, Property, DataType
import datetime

client.collections.create(
    name="CollectionWithTTL",
    properties=[
        Property(name="referenceDate", data_type=DataType.DATE),
    ],
    object_ttl_config=Configure.ObjectTTL.delete_by_update_time(
        time_to_live=datetime.timedelta(days=10),  # Or set 864000 for seconds
        filter_expired_objects=True,  # Optional: automatically filter out expired objects from queries
    ),
)
```
:::

:::tab{title="JavaScript/TypeScript"}
```typescript
await client.collections.create({
  name: 'CollectionWithTTL',
  properties: [
    { name: 'referenceDate', dataType: dataType.DATE },
  ],
  objectTTL: configure.objectTTL.deleteByUpdateTime({
    defaultTTLSeconds: 864000,  // 10 days
    filterExpiredObjects: true,  // Optional: automatically filter out expired objects from queries
  }),
});
```
:::

:::tab{title="Java"}
```java
client.collections.create("CollectionWithTTL",
    c -> c.properties(Property.date("referenceDate"))
        .objectTtl(ttl -> ttl
            .deleteByUpdateTime()
            .defaultTtlSeconds(864000)  // 10 days
            .filterExpiredObjects(true)  // Optional: automatically filter out expired objects from queries
        ));
```
:::

  <!-- <TabItem value="csharp" label="C#">
    <FilteredTextBlock
      text=
      startMarker="// START TTLByUpdateTime"
      endMarker="// END TTLByUpdateTime"
      language="csharp"
    />
  </TabItem> -->
::::

## Relative to a specific DATE property

Set a TTL to a relative value from a specific `DATE` property within the object. The value can be positive or negative.

::::tabs{sync="languages"}
:::tab{title="Python"}
```python
from weaviate.classes.config import Configure, Property, DataType
import datetime

client.collections.create(
    name="CollectionWithTTL",
    properties=[
        Property(name="referenceDate", data_type=DataType.DATE),
    ],
    object_ttl_config=Configure.ObjectTTL.delete_by_date_property(
        property_name="referenceDate",
        ttl_offset=datetime.timedelta(minutes=5),
    ),
)
```
:::

:::tab{title="JavaScript/TypeScript"}
```typescript
await client.collections.create({
  name: 'CollectionWithTTL',
  properties: [
    { name: 'referenceDate', dataType: dataType.DATE },
  ],
  objectTTL: configure.objectTTL.deleteByDateProperty({
    property: 'referenceDate',
    defaultTTLSeconds: 300,  // 5 minutes offset
  }),
});
```
:::

:::tab{title="Java"}
```java
client.collections.create("CollectionWithTTL",
    c -> c.properties(Property.date("referenceDate"))
        .objectTtl(ttl -> ttl
            .deleteByDateProperty("referenceDate")
            .defaultTtlSeconds(300)  // 5 minutes offset
        ));
```
:::

  <!-- <TabItem value="csharp" label="C#">
    <FilteredTextBlock
      text=
      startMarker="// START TTLByDateProperty"
      endMarker="// END TTLByDateProperty"
      language="csharp"
    />
  </TabItem> -->
::::

## Further resources

- [Concepts: Data | Time to live](../concepts/data.md#time-to-live-ttl)
- [References: Environment variables](../database-configuration/overview.md)

## Questions and feedback

Have a question or feedback? Here's how to reach us.

::::card-grid
:::card{title="Community Forum" href="https://forum.weaviate.io/c/support" icon="messages-square"}
Ask questions and connect with other developers on our **Community forum**.
:::

:::card{title="Support" href="/guides/support-overview" icon="life-buoy"}
Weaviate Cloud user or customer? Find the right channel on the **Support page**.
:::
::::

## Related pages

- [Agents](./agents-index.md)
- [AI-assisted Weaviate code generation](./ai-assisted-vibe-coding-index.md)
- [APIs](./apis-index.md)
- [Authorization and authentication](./authorization-and-authentication-index.md)
- [Benchmarks](./benchmarks-index.md)
- [Best practices](./best-practices-index.md)
- [Client libraries](./clients-index.md)
- [Client Libraries / SDKs](./client-libraries-index.md)
- [Cloud](./cloud-index.md)
- [Cloud account management](./cloud-account-management-index.md)

# Agent Instructions

This portal answers questions programmatically. To receive a synthesized,
source-cited answer instead of crawling page by page, append the `?ask=`
query parameter to any page URL on this site:

    /guides/quickstart?ask=how+do+I+authenticate

Optional parameters:

- `&goal=<what-you-are-trying-to-do>` steers the answer toward your
  objective (e.g. `&goal=write+a+python+client`).
- `&version=<label>` scopes the answer to a mounted version when the
  portal publishes more than one.

The response is `text/markdown`: the answer followed by a `# Sources` list
of the portal pages it was grounded in. Status codes are the contract:

- `200` — the answer; `402` — the portal owner’s plan or answer credits are
  exhausted (surface this to your operator; do NOT retry); `429` — you are
  rate-limited; back off for the `Retry-After` seconds; `503` — the answer
  lane is temporarily unavailable; fall back to crawling the `.md` pages.

For the full corpus map read `llms.txt` at the site root; for the tool
surface (search + page fetch as MCP tools) see `/mcp`.
