Notebooks
W
Weaviate
Transformation Agent Sleep Time Compute

Transformation Agent Sleep Time Compute

vector-searchagentsvector-databaseretrieval-augmented-generationllm-frameworksfunction-callingweaviate-recipesPythongenerative-aiweaviate-services

Open In Colab

Sleep-time Compute with Weaviate Agents

This notebook will showcase how Weaviate Agents can help you build systems that utilize Sleep-time Compute!

"Sleep-time compute is a new way to scale AI capabilities, letting models "think" during downtime. Instead of sitting idle between tasks, AI agents can now use their "sleep" time to process information and form new connections by rewriting their memory state." Letta AI

This notebook reproduces the concept in the paper. Extracting predicted questions for each document in a collection of documents. We then use these predicted questions to create an enhanced set of documents. We achieve this with the Weaviate Transformation Agent!

  1. We begin by chunking Weaviate's blog posts and importing them to Weaviate, resulting in 1,463 objects.

  2. We then run the Transformation Agent to predict potential questions from each chunk. This produces 12 questions per chunk on average. This takes the Transformation Agent 2.5 minutes!

  3. We then create new objects for each <chunk, predicted_user_query> pair, resulting in 17,933 objects.

  4. We then run the Transformation Agent to create enhanced_content for each of the 17,933 objects. This takes the Transformation Agent 12 minutes!

This notebook also contains interleaved examples using the Query Agent to inspect the results of the Transformation Agent! ♻️

1. Import Weaviate Blogs to Weaviate

If interested in using this dataset particularly, you can get it by cloning weaviate-io on github from this link. The markdown files for Weaviate's blogs are in the blog folder.

[ ]
[24]
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/weaviate/collections/classes/config.py:1950: PydanticDeprecatedSince211: Accessing this attribute on the instance is deprecated, and will be removed in Pydantic V3. Instead, you should access this attribute from the model class. Deprecated in Pydantic V2.11 to be removed in V3.0.
  for cls_field in self.model_fields:
Successfully imported 1463 blog chunks into Weaviate.
Upload time: 8.76 seconds

2. Predict Questions per Chunk

[25]
[27]
{'workflow_id': 'TransformationWorkflow-aa4204ddb0b56291823cb50cf8be9ff1',
, 'status': {'batch_count': 6,
,  'end_time': '2025-04-27 17:50:57',
,  'start_time': '2025-04-27 17:48:13',
,  'state': 'completed',
,  'total_duration': 164.486092,
,  'total_items': 1463}}
[28]
Content:
refs/schema/vector-index#hnsw-configuration-tips) to help with your use case!

### Text Search Configuration
Weaviate lets you tune how each property is indexed, or if they’re indexed at all! By skipping the indexes, you speed up the insert time and reduce the memory for indexing.

In this demo, we determined that search performance could be improved by exactly matching a particular `title` value. This requires creating an inverted index to find text matches on the `title` property. This is denoted in your schema by setting `indexFilterable` to `True`. We further want to use BM25 scoring on the title, so we create an inverted index for keyword scoring as well. This is achieved by setting `indexSearchable` to `True`. However, for the `url` and `content` properties, although we want the data stored, we do not need an index, so we turn it off by setting both `indexFilterable` and `indexSearchable` to `False`.

### Batch Imports
When importing data into Weaviate, we suggest using batch imports. This will send multiple objects in a single request, rather than importing them individually. There are [three methods](/developers/weaviate/client-libraries/python#batch-sizing) to choose from:

1. `dynamic`: The batch size and number of requests are dynamically adjusted as you import data. The size and number of each are dependent on the server load.

```python


Predicted User Queries:
1. How does Weaviate manage indexing?
2. What happens when I skip indexes in Weaviate?
3. Why is determining the right indexing strategy important for search performance?
4. What type of index is needed for exact match on a 'title' value?
5. How can I improve search performance for a specific 'title' value in Weaviate?
6. What is BM25 scoring used for in Weaviate?
7. Can I disable indexing for certain properties in Weaviate?
8. Which method should I use for importing data into Weaviate?
9. What are the benefits of using batch imports in Weaviate?
10. How does dynamic batch sizing work in Weaviate?

Inspect the results of the Transformation Agent with the Query Agent! ♻️

[30]


3. Create a Unique Object for each Predicted Query

[31]
[32]
Starting data collection...
Data collection completed in 1.03 seconds
Found 17933 objects to create and 1463 objects to update
Starting batch insert for EnhancedBlogs...
Batch insert completed in 79.05 seconds
Inserted 17933 objects into EnhancedBlogs collection
Starting batch update for Blogs collection...
Batch update completed in 7.19 seconds
Updated 1463 objects in Blogs collection
Total execution time: 87.27 seconds
Created 17933 new objects with individual predicted queries in EnhancedBlogs collection
Skipped 0 objects with no predicted queries
Removed predicted_user_queries property from 1463 source objects in Blogs collection

4. Create Enhanced Content by Reasoning about the Predicted Query and the Original Content

[33]
[34]
{'workflow_id': 'TransformationWorkflow-1f5817a983af680f4830de8801cd8b2b',
, 'status': {'batch_count': 72,
,  'end_time': '2025-04-27 18:06:36',
,  'start_time': '2025-04-27 17:54:42',
,  'state': 'completed',
,  'total_duration': 714.313995,
,  'total_items': 17933}}
[53]


[54]


[63]
QueryReturn with 1 objects:

Object 1:
  UUID: 15b591a9-eaa3-4989-bf9a-ed469a4a045f
  Properties:
    content: /weaviate/recipes/blob/main/weaviate-services/agents/transformation-agent-get-started.ipynb#scrollTo=Uiu5C8n7v-Xp) that you can use to get started.

⚠️ Since this service is currently in preview, please do not demo it on production collections.
:::

## What is the Transformation Agent

This is our first step into a future of database management where we can start to leave the tedious task of designing updates and changes for our database to an LLM.

You can configure the `TransformationAgent` to access any given collection in Weaviate Cloud and provide it with a list of transformation operations you’d like to perform on it.

For example, think of a scenario where you may have quarterly reports from teams in your company in a collection. With the transformation agent, you can define new properties such as “team” or “quarter” with the instructions “Based on the contents of the report, identify what team it’s from” or “Based on the report, identify what quarter the report belongs to”. The agent will take care of 2 of the most important steps in this scenario:

1.  It will determine the team and quarter of the report with the use of an LLM
2.  It will also then create the additional properties and write them to each report object in Weaviate.

Not only that, the agent will do this for all objects in our collection. While these may seem like
    enhanced_content: The Transformation Agent is a service in Weaviate Cloud that enables automating updates and changes to a database by using a Large Language Model (LLM). This agent allows users to access any given collection in Weaviate and apply a list of predefined transformation operations. For instance, if a company has quarterly reports in a collection, the agent can be configured to extract specific details such as 'team' and 'quarter' based on the report content.

Key concepts:
- Transformation Agent
- Weaviate Cloud
- Large Language Model (LLM)
- Collection
Relationships:
- The Transformation Agent accesses collections in Weaviate Cloud
- The agent uses an LLM to analyze report content
- The agent creates new properties ('team', 'quarter') and writes them to each report object
Inference:
The Transformation Agent streamlines the process of updating and modifying databases by leveraging AI-driven analysis.

Structured information:
*   **What is the Transformation Agent?**: A service that utilizes an LMM to automate updates and modifications to a database.
*   **How does the Transformation Agent work?**: It accesses a specified collection, applies a set of transformation operations, and generates new properties based on the analysis of report content.
*   **Benefits of the Transformation Agent**: Reduces manual effort required for database updates and modification, increases efficiency.
Answering the predicted user query: How will the Transformation Agent affect my existing objects in Weaviate?

The Transformation Agent will update existing objects in Weaviate by generating new properties ('team', 'quarter') based on the analysis of their content.
    predicted_user_query: How will the Transformation Agent affect my existing objects in Weaviate?