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:
qinling0210
2026-03-17 16:45:45 +08:00
committed by GitHub
parent 549833b8a4
commit ca182dc188
9 changed files with 1023 additions and 303 deletions

View File

@@ -20,24 +20,66 @@ import (
"context"
"fmt"
"ragflow/internal/server"
"strconv"
"strings"
infinity "github.com/infiniflow/infinity-go-sdk"
)
// Engine Infinity engine implementation
// Note: Infinity Go SDK is not yet available. This is a placeholder implementation.
// infinityClient Infinity SDK client wrapper
type infinityClient struct {
conn *infinity.InfinityConnection
dbName string
}
// NewInfinityClient creates a new Infinity client using the SDK
func NewInfinityClient(cfg *server.InfinityConfig) (*infinityClient, error) {
// Parse URI like "localhost:23817" to get IP and port
host := "127.0.0.1"
port := 23817
if cfg.URI != "" {
parts := strings.Split(cfg.URI, ":")
if len(parts) == 2 {
host = parts[0]
if p, err := strconv.Atoi(parts[1]); err == nil {
port = p
}
}
}
conn, err := infinity.Connect(infinity.NetworkAddress{IP: host, Port: port})
if err != nil {
return nil, fmt.Errorf("failed to connect to Infinity: %w", err)
}
return &infinityClient{
conn: conn,
dbName: cfg.DBName,
}, nil
}
// Engine Infinity engine implementation using Go SDK
type infinityEngine struct {
config *server.InfinityConfig
client *infinityClient
}
// NewEngine creates an Infinity engine
// Note: This is a placeholder implementation waiting for official Infinity Go SDK
func NewEngine(cfg interface{}) (*infinityEngine, error) {
infConfig, ok := cfg.(*server.InfinityConfig)
if !ok {
return nil, fmt.Errorf("invalid infinity config type, expected *config.InfinityConfig")
}
client, err := NewInfinityClient(infConfig)
if err != nil {
return nil, err
}
engine := &infinityEngine{
config: infConfig,
client: client,
}
return engine, nil
@@ -48,12 +90,22 @@ func (e *infinityEngine) Type() string {
return "infinity"
}
// Ping health check
// Ping checks if Infinity is accessible
func (e *infinityEngine) Ping(ctx context.Context) error {
return fmt.Errorf("infinity engine not implemented: waiting for official Go SDK")
}
// Close closes the connection
func (e *infinityEngine) Close() error {
if e.client == nil || e.client.conn == nil {
return fmt.Errorf("Infinity client not initialized")
}
if !e.client.conn.IsConnected() {
return fmt.Errorf("Infinity not connected")
}
return nil
}
// Close closes the Infinity connection
func (e *infinityEngine) Close() error {
if e.client != nil && e.client.conn != nil {
_, err := e.client.conn.Disconnect()
return err
}
return nil
}