> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # Memory.listThreads() 그만큼`listThreads()`메소드는 페이지 매김 지원 및 선택적 필터링을 통해 스레드를 검색합니다.`resourceId`, `metadata`, 또는 둘 다. ## 사용 예 ### 페이지 매김을 사용하여 모든 스레드 나열 ```typescript const result = await memory.listThreads({ page: 0, perPage: 10, }) ``` ### 페이지 매김 없이 모든 스레드 가져오기 사용`perPage: false` to retrieve all matching threads at once. > **경고:** 특히 대규모 데이터세트의 경우 페이지 매김을 사용하세요. 이 옵션은 주의해서 사용하세요. ```typescript const result = await memory.listThreads({ filter: { resourceId: 'user-123' }, perPage: false, }) ``` ### 필터링 기준`resourceId` ```typescript const result = await memory.listThreads({ filter: { resourceId: 'user-123' }, page: 0, perPage: 10, }) ``` ### 메타데이터로 필터링 ```typescript const result = await memory.listThreads({ filter: { metadata: { category: 'support', priority: 'high' } }, page: 0, perPage: 10, }) ``` ### 결합된 필터(resourceId 및 메타데이터) ```typescript const result = await memory.listThreads({ filter: { resourceId: 'user-123', metadata: { status: 'active' }, }, page: 0, perPage: 10, }) ``` ## 매개변수 **filter** (`{ resourceId?: string; metadata?: Record }`): Optional filter object. resourceId filters threads by resource ID. metadata filters threads by metadata key-value pairs (AND logic - all must match) **page** (`number`): Page number (0-indexed) to retrieve **perPage** (`number | false`): Maximum number of threads to return per page, or false to fetch all **orderBy** (`{ field: 'createdAt' | 'updatedAt', direction: 'ASC' | 'DESC' }`): Sort configuration with field and direction (defaults to { field: 'createdAt', direction: 'DESC' }) ## 보고 **result** (`Promise`): A promise that resolves to paginated thread results with metadata 반환 개체에는 다음이 포함됩니다. - `threads`: 스레드 객체 배열 - `total`: 필터와 일치하는 총 스레드 수 - `page`: 현재 페이지 번호(입력과 동일)`page` parameter) - `perPage`: 페이지당 항목 수(입력과 동일)`perPage` parameter) - `hasMore`: 더 많은 결과가 있는지 나타내는 부울 ## 확장된 사용 예 ```typescript import { mastra } from './mastra' const agent = mastra.getAgent('agent') const memory = await agent.getMemory() let currentPage = 0 const perPage = 25 let hasMorePages = true // Fetch all active threads for a user, sorted by creation date while (hasMorePages) { const result = await memory?.listThreads({ filter: { resourceId: 'user-123', metadata: { status: 'active' }, }, page: currentPage, perPage: perPage, orderBy: { field: 'createdAt', direction: 'ASC' }, }) if (!result) { console.log('No threads') break } result.threads.forEach(thread => { console.log(`Thread: ${thread.id}, Created: ${thread.createdAt}`) }) hasMorePages = result.hasMore currentPage++ // Move to next page } ``` ## 메타데이터 필터링 메타데이터 필터는 AND 논리를 사용합니다. 스레드가 결과에 포함되려면 지정된 모든 키-값 쌍이 일치해야 합니다. ```typescript // This will only return threads where BOTH conditions are true: // - category === 'support' // - priority === 'high' await memory.listThreads({ filter: { metadata: { category: 'support', priority: 'high', }, }, }) ``` ## 관련된 - [Memory 클래스 참조](https://mastra.zisheng.pro/ko/reference/memory/memory-class) - [Memory 시작하기](https://mastra.zisheng.pro/ko/docs/memory/overview) - [생성스레드](https://mastra.zisheng.pro/ko/reference/memory/createThread) - [getThreadById](https://mastra.zisheng.pro/ko/reference/memory/getThreadById)