feat: Support filtering chunks by multiple chunk_type params
This commit is contained in:
+6
-1
@@ -75,19 +75,24 @@ type UpdateChunkRequest struct {
|
|||||||
// - knowledgeID: Knowledge ID
|
// - knowledgeID: Knowledge ID
|
||||||
// - page: Page number, starts from 1
|
// - page: Page number, starts from 1
|
||||||
// - pageSize: Number of items per page
|
// - pageSize: Number of items per page
|
||||||
|
// - chunkTypes: Optional chunk type filter (e.g. "text", "image_caption", "image_ocr").
|
||||||
|
// When empty, the server defaults to text chunks only.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - []Chunk: List of chunks
|
// - []Chunk: List of chunks
|
||||||
// - int64: Total count
|
// - int64: Total count
|
||||||
// - error: Error information
|
// - error: Error information
|
||||||
func (c *Client) ListKnowledgeChunks(ctx context.Context,
|
func (c *Client) ListKnowledgeChunks(ctx context.Context,
|
||||||
knowledgeID string, page int, pageSize int,
|
knowledgeID string, page int, pageSize int, chunkTypes ...string,
|
||||||
) ([]Chunk, int64, error) {
|
) ([]Chunk, int64, error) {
|
||||||
path := fmt.Sprintf("/api/v1/chunks/%s", knowledgeID)
|
path := fmt.Sprintf("/api/v1/chunks/%s", knowledgeID)
|
||||||
|
|
||||||
queryParams := url.Values{}
|
queryParams := url.Values{}
|
||||||
queryParams.Add("page", strconv.Itoa(page))
|
queryParams.Add("page", strconv.Itoa(page))
|
||||||
queryParams.Add("page_size", strconv.Itoa(pageSize))
|
queryParams.Add("page_size", strconv.Itoa(pageSize))
|
||||||
|
for _, ct := range chunkTypes {
|
||||||
|
queryParams.Add("chunk_type", ct)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := c.doRequest(ctx, http.MethodGet, path, nil, queryParams)
|
resp, err := c.doRequest(ctx, http.MethodGet, path, nil, queryParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -128,7 +128,14 @@ func (h *ChunkHandler) ListKnowledgeChunks(c *gin.Context) {
|
|||||||
pagination.PageSize = 100
|
pagination.PageSize = 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default to text chunks; callers may override via ?chunk_type=image_caption etc.
|
||||||
chunkType := []types.ChunkType{types.ChunkTypeText}
|
chunkType := []types.ChunkType{types.ChunkTypeText}
|
||||||
|
if queryTypes := c.QueryArray("chunk_type"); len(queryTypes) > 0 {
|
||||||
|
chunkType = make([]types.ChunkType, 0, len(queryTypes))
|
||||||
|
for _, qt := range queryTypes {
|
||||||
|
chunkType = append(chunkType, types.ChunkType(qt))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The route-level guard has rewritten the request's tenant context
|
// The route-level guard has rewritten the request's tenant context
|
||||||
// to the effective tenant for shared KBs.
|
// to the effective tenant for shared KBs.
|
||||||
|
|||||||
Reference in New Issue
Block a user