Using Groups with Trieve
Learn how to create and use groups with Trieve
Overview
We provide the ability to cluster and structure related chunks of data. This allows for specific search and recommendation paradigms — constraining results to specific groups.
Groups vs Tags
Tags provide users the ability, through the tag_set
attribute in chunks and groups, to categorize and label specific chunks, allowing for quick filtering. This lacks many of the higher level functionality around groups, which allow you to organize and search related content at a broader level.
Creating Groups
To create a group, use the create or upsert group API route.
Important Parameters
name
: The name of the group. This does not need to be unique.description
: A description of the group and its corresponding chunks.metadata
: A JSON object containing any additional information to associate with chunks in this chunk group.tracking_id
: An optional, unique identifier to assign to this chunk group.tag_set
: A list of strings to categorize chunks within this chunk group.
Accessing Chunks in a Group
Trieve allows you to assign unique, arbitrary IDs to groups, through the group_tracking_id
field, to sync with external systems. This also means that you can access and search groups using this field.
For example, to fetch all chunks in a group by the group_tracking_id
, use the get chunks in group by tracking ID route.
Adding Chunks to Groups
To add an existing chunk to a group, use the add chunk to group route.
group_id
is the Trieve generated ids for groups whereas the
group_tracking_id
is a user-assigned tracking_ids for groups. Groups
with group_ids
must be created first and cannot be arbitrarily created.
To assign a chunk to a group on creation, use the create or upsert chunk or chunks route and specify the group_ids
or group_tracking_ids
. Specify one or more existing group IDs that the chunks should be placed into, or provide group tracking IDs. If any IDs within the list of group_tracking_ids
do not exist, new groups corresponding to those tracking IDs will be created.
View Groups in Search Playground
Once you create a group and assign chunks, you can easily view and manage these groups through the search playground.
To view groups:
- Navigate and login to the search playground at https://search.trieve.ai/.
- Click on
Groups
in the Navbar. - View group details (such as name, description, and date created).
- Click on any group name to access its corresponding chunks.
Searching Groups
In addition to searching over independent chunks, we allow users to search within groups and search over groups.
Search over groups returns the groups of chunks similar to the search query while search within groups restricts the search to a single group.
Search over groups can be performed similar to search over chunks (checkout guide here), with the addition of the group_size
field to specify the number of chunks to fetch for each group.
Similarly, to search within a group, use the group_id
or group_tracking_id
fields to specify which group you want to search in.
Recommendations Groups
Trieve also provides the ability to get recommended groups and recommended chunks within a group through the get recommended groups and the get recommended chunks routes.
Fetching recommended groups through the get recommended groups route is similiar to using the get recommended chunks route (checkout guide here), with the addition of:
positive_group_tracking_ids
: the tracking IDs of groups that serve as positive examples when curating recommendations.negative_group_tracking_ids
: the tracking IDs of groups that serve as negative examples when getting recommendations.group_size
: the number of chunks to be fetched for each group.limit
: the max number of groups (rather than chunks) that should be returned.
To get recommended chunks within a group, you can use the get_recommended_chunks
route with a filter on group_ids
or group_tracking_ids
.