mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-06-04 21:34:31 +08:00
feat: Support filtering chunks by multiple chunk_type params
This commit is contained in:
@@ -75,19 +75,24 @@ type UpdateChunkRequest struct {
|
||||
// - knowledgeID: Knowledge ID
|
||||
// - page: Page number, starts from 1
|
||||
// - 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:
|
||||
// - []Chunk: List of chunks
|
||||
// - int64: Total count
|
||||
// - error: Error information
|
||||
func (c *Client) ListKnowledgeChunks(ctx context.Context,
|
||||
knowledgeID string, page int, pageSize int,
|
||||
knowledgeID string, page int, pageSize int, chunkTypes ...string,
|
||||
) ([]Chunk, int64, error) {
|
||||
path := fmt.Sprintf("/api/v1/chunks/%s", knowledgeID)
|
||||
|
||||
queryParams := url.Values{}
|
||||
queryParams.Add("page", strconv.Itoa(page))
|
||||
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)
|
||||
if err != nil {
|
||||
|
||||
@@ -128,7 +128,14 @@ func (h *ChunkHandler) ListKnowledgeChunks(c *gin.Context) {
|
||||
pagination.PageSize = 100
|
||||
}
|
||||
|
||||
// Default to text chunks; callers may override via ?chunk_type=image_caption etc.
|
||||
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
|
||||
// to the effective tenant for shared KBs.
|
||||
|
||||
Reference in New Issue
Block a user