mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-01 07:47:47 +08:00
Implement Search() in Infinity in GO (#13645)
### What problem does this PR solve? Implement Search() in Infinity in GO. The function can handle the following request. "search '曹操' on datasets 'infinity'" "search '常胜将军' on datasets 'infinity'" "search '卓越儒雅' on datasets 'infinity'" "search '辅佐刘禅北伐中原' on datasets 'infinity'" The output is exactly the same as request to python Search() ### Type of change - [ ] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -31,9 +31,9 @@ type PasswordPromptFunc func(prompt string) (string, error)
|
||||
|
||||
// RAGFlowClient handles API interactions with the RAGFlow server
|
||||
type RAGFlowClient struct {
|
||||
HTTPClient *HTTPClient
|
||||
ServerType string // "admin" or "user"
|
||||
PasswordPrompt PasswordPromptFunc // Function for password input
|
||||
HTTPClient *HTTPClient
|
||||
ServerType string // "admin" or "user"
|
||||
PasswordPrompt PasswordPromptFunc // Function for password input
|
||||
}
|
||||
|
||||
// NewRAGFlowClient creates a new RAGFlow client
|
||||
@ -489,6 +489,28 @@ func (c *RAGFlowClient) getDatasetID(datasetName string) (string, error) {
|
||||
return "", fmt.Errorf("dataset '%s' not found", datasetName)
|
||||
}
|
||||
|
||||
// formatEmptyArray converts empty arrays to "[]" string
|
||||
func formatEmptyArray(v interface{}) string {
|
||||
if v == nil {
|
||||
return "[]"
|
||||
}
|
||||
switch val := v.(type) {
|
||||
case []interface{}:
|
||||
if len(val) == 0 {
|
||||
return "[]"
|
||||
}
|
||||
case []string:
|
||||
if len(val) == 0 {
|
||||
return "[]"
|
||||
}
|
||||
case []int:
|
||||
if len(val) == 0 {
|
||||
return "[]"
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%v", v)
|
||||
}
|
||||
|
||||
// SearchOnDatasets searches for chunks in specified datasets
|
||||
// Returns (result_map, error) - result_map is non-nil for benchmark mode
|
||||
func (c *RAGFlowClient) SearchOnDatasets(cmd *Command) (map[string]interface{}, error) {
|
||||
@ -582,6 +604,22 @@ func (c *RAGFlowClient) SearchOnDatasets(cmd *Command) (map[string]interface{},
|
||||
"term_similarity": chunkMap["term_similarity"],
|
||||
"vector_similarity": chunkMap["vector_similarity"],
|
||||
}
|
||||
// Add optional fields that may be empty arrays
|
||||
if v, ok := chunkMap["doc_type_kwd"]; ok {
|
||||
row["doc_type_kwd"] = formatEmptyArray(v)
|
||||
}
|
||||
if v, ok := chunkMap["important_kwd"]; ok {
|
||||
row["important_kwd"] = formatEmptyArray(v)
|
||||
}
|
||||
if v, ok := chunkMap["mom_id"]; ok {
|
||||
row["mom_id"] = formatEmptyArray(v)
|
||||
}
|
||||
if v, ok := chunkMap["positions"]; ok {
|
||||
row["positions"] = formatEmptyArray(v)
|
||||
}
|
||||
if v, ok := chunkMap["content_ltks"]; ok {
|
||||
row["content_ltks"] = v
|
||||
}
|
||||
tableData = append(tableData, row)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user