yao/kb/api/interfaces.go
Max 01820d9fe2 Add function execution support to Job system
- Introduced `AddFunc` method to the `Job` struct for adding Go functions as job executions, allowing for dynamic execution of functions with specified arguments.
- Enhanced internal execution handling to register functions in a global registry, ensuring proper cleanup after execution.
- Implemented `ExecuteFunc` method in the `Goroutine` struct to handle the execution of registered functions, including error handling and context management.
- Added comprehensive unit tests for `AddFunc`, verifying function registration, execution, and memory cleanup post-execution.
- Updated related documentation to reflect the new functionality and usage patterns for adding and executing Go functions within the job system.
2025-12-19 14:50:53 +08:00

45 lines
2 KiB
Go

package api
import (
"context"
"github.com/yaoapp/gou/graphrag/types"
kbtypes "github.com/yaoapp/yao/kb/types"
)
// API defines the unified interface for all KB operations
type API interface {
// Collection operations
CreateCollection(ctx context.Context, params *CreateCollectionParams) (*CreateCollectionResult, error)
RemoveCollection(ctx context.Context, collectionID string) (*RemoveCollectionResult, error)
GetCollection(ctx context.Context, collectionID string) (map[string]interface{}, error)
CollectionExists(ctx context.Context, collectionID string) (*CollectionExistsResult, error)
ListCollections(ctx context.Context, filter *ListCollectionsFilter) (*ListCollectionsResult, error)
UpdateCollectionMetadata(ctx context.Context, collectionID string, params *UpdateMetadataParams) (*UpdateMetadataResult, error)
// Document operations
ListDocuments(ctx context.Context, filter *ListDocumentsFilter) (*ListDocumentsResult, error)
GetDocument(ctx context.Context, docID string, params *GetDocumentParams) (map[string]interface{}, error)
RemoveDocuments(ctx context.Context, params *RemoveDocumentsParams) (*RemoveDocumentsResult, error)
// Document add operations (sync)
AddFile(ctx context.Context, params *AddFileParams) (*AddDocumentResult, error)
AddText(ctx context.Context, params *AddTextParams) (*AddDocumentResult, error)
AddURL(ctx context.Context, params *AddURLParams) (*AddDocumentResult, error)
// Document add operations (async)
AddFileAsync(ctx context.Context, params *AddFileParams) (*AddDocumentAsyncResult, error)
AddTextAsync(ctx context.Context, params *AddTextParams) (*AddDocumentAsyncResult, error)
AddURLAsync(ctx context.Context, params *AddURLParams) (*AddDocumentAsyncResult, error)
// Segment operations (future)
// ...
}
// KBInstance holds the KB instance dependencies required by the API
type KBInstance struct {
GraphRag types.GraphRag // GraphRag instance
// for vector/graph operations
Config *kbtypes.Config // KB configuration
Providers *kbtypes.ProviderConfig // Provider configurations
}