Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdpierse committed Sep 24, 2024
1 parent 721c4f2 commit af17f95
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions docs/3_add_items_and_interactions.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Adding Items and User Interactions

## Overview
This guide explains how to add items to your recommender system and record user interactions using the `WeaviateRecommendClient`.

This guide explains how to add items to your recommender system, record user interactions, and manage user data using the `WeaviateRecommendClient`.

## Prerequisites

- Established connection to the Recommender Service (see `1_connection.md`)
- Created recommender schema (see `2_create_schema.md`)

Expand Down Expand Up @@ -45,13 +47,37 @@ response = client.item.add_batch(items)
print(response)
```

## Recording User Interactions
## Managing User Data

### Creating a New User

To record a single user interactions with an item:
To create a new user in the recommender system:

```python
from weaviate_recommend.models.data import UserInteraction
from weaviate_recommend.models.data import User

new_user = User(id="user123", properties={"name": "John Doe", "age": 30})
response = client.user.create_user(new_user)
print(response)
```

### Retrieving User Information

To get all properties for a user by ID:

```python
user_id = "user123"
user = client.user.get_user(user_id)
print(user)
```

## Recording User Interactions

### Adding a Single User Interaction

To record a single user interaction with an item:

```python
user_id = "user123"
item_id = "item456"
interaction_type = "purchase" # Or "like", "view", etc. as defined in your schema
Expand All @@ -71,22 +97,37 @@ print(response)
For bulk addition of user interactions:

```python
from weaviate_recommend.models.data import UserInteraction

interactions = [
UserInteraction(user_id="user1", "item_id": "1", "interaction_property_name": "purchase", "weight": 1.0},
UserInteraction(user_id="user1", "item_id": "4", "interaction_property_name": "purchase", "weight": 0.5},
# add more items as needed
UserInteraction(user_id="user1", item_id="1", interaction_property_name="purchase", weight=1.0),
UserInteraction(user_id="user1", item_id="4", interaction_property_name="purchase", weight=0.5),
# add more interactions as needed
]

client.user.add_interactions(interactions)
response = client.user.add_interactions(interactions)
print(response)
```

### Retrieving User Interactions

To get all interactions for a specific user:

```python
user_id = "user123"
interactions = client.user.get_user_interactions(user_id)
for interaction in interactions:
print(f"Item: {interaction.item_id}, Type: {interaction.interaction_property_name}, Weight: {interaction.weight}")
```

## Best Practices

1. Ensure all required properties are included when adding items.
1. Ensure all required properties are included when adding items or creating users.
2. Use batch operations for adding multiple items or user interactions efficiently.
3. Choose appropriate weights for user interactions to reflect their importance.
4. Regularly add user interactions to keep the recommender system up-to-date.
5. Use the `get_user` and `get_user_interactions` methods to retrieve and analyze user data as needed.

## Next Steps

After adding items and user interactions, you can train your recommender system to generate personalized recommendations. See `4_train.md` for information on training the system.
After adding items, managing user data, and recording user interactions, you can train your recommender system to generate personalized recommendations. See `4_train.md` for information on training the system.

0 comments on commit af17f95

Please sign in to comment.