http

package module
v0.0.0-...-dc0b5c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 8 Imported by: 1

README

Feast HTTP 扩展包

Feast HTTP 客户端实现,位于扩展包中,独立管理依赖。

架构说明

领域层接口feature.FeatureService(核心包)

  • 这是推荐使用的接口,位于领域层
  • 所有特征服务都应实现此接口

基础设施层接口ext/feast/http.Client(扩展包)

  • 这是 Feast 特定的接口,位于基础设施层
  • 主要用于适配器内部使用

推荐使用方式:通过适配器将 Feast 适配为 feature.FeatureService

安装

go get github.com/rushteam/reckit/ext/feast/http

使用方式

方式 1:通过适配器使用(推荐)
import (
    "github.com/rushteam/reckit/feature"
    feasthttp "github.com/rushteam/reckit/ext/feast/http"
)

// 1. 创建 Feast HTTP 客户端(基础设施层)
feastClient, err := feasthttp.NewClient("http://localhost:6566", "my_project")
if err != nil {
    log.Fatal(err)
}
defer feastClient.Close()

// 2. 创建特征映射配置
mapping := &feasthttp.FeatureMapping{
    UserFeatures: []string{"user_stats:age", "user_stats:gender"},
    ItemFeatures: []string{"item_stats:price", "item_stats:category"},
    UserEntityKey: "user_id",
    ItemEntityKey: "item_id",
}

// 3. 创建适配器(将 Feast 适配为 feature.FeatureService)
featureService := feasthttp.NewFeatureServiceAdapter(feastClient, mapping)

// 4. 作为 feature.FeatureService 使用(领域层接口)
var fs feature.FeatureService = featureService
方式 2:直接使用 Feast 客户端(不推荐)
import feasthttp "github.com/rushteam/reckit/ext/feast/http"

// 直接使用基础设施层接口(不推荐,应使用领域层接口)
client, err := feasthttp.NewClient("http://localhost:6566", "my_project")
var c feasthttp.Client = client

依赖

  • github.com/rushteam/reckit - 核心包(领域层接口 feature.FeatureService

自行实现

你也可以参考此实现,自行实现 feature.FeatureService 接口,满足你的特定需求。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	// Type 认证类型:basic, bearer, api_key, static
	Type string

	// Username 用户名(basic auth)
	Username string

	// Password 密码(basic auth)
	Password string

	// Token Token(bearer auth 或 static auth)
	Token string

	// APIKey API Key(api_key auth)
	APIKey string
}

AuthConfig 认证配置

type Client

type Client interface {
	// GetOnlineFeatures 获取在线特征(用于实时预测)
	GetOnlineFeatures(ctx context.Context, req *GetOnlineFeaturesRequest) (*GetOnlineFeaturesResponse, error)

	// GetHistoricalFeatures 获取历史特征(用于训练数据)
	GetHistoricalFeatures(ctx context.Context, req *GetHistoricalFeaturesRequest) (*GetHistoricalFeaturesResponse, error)

	// Materialize 将特征物化到在线存储
	Materialize(ctx context.Context, req *MaterializeRequest) error

	// ListFeatures 列出所有可用的特征
	ListFeatures(ctx context.Context) ([]Feature, error)

	// GetFeatureService 获取特征服务信息
	GetFeatureService(ctx context.Context) (*FeatureServiceInfo, error)

	// Close 关闭客户端连接
	Close() error
}

Client 是 Feast Feature Store 的客户端接口。

注意:此接口位于扩展包中,是基础设施层接口。 领域层应使用 feature.FeatureService 接口。

参考:https://github.com/feast-dev/feast

func NewClient

func NewClient(endpoint, project string, opts ...ClientOption) (Client, error)

NewClient 统一的客户端创建函数,创建 HTTP 客户端。

注意:此实现位于扩展包中,需要单独引入:

go get github.com/rushteam/reckit/ext/feast/http

func NewClientWithContext

func NewClientWithContext(ctx context.Context, endpoint, project string, opts ...ClientOption) (Client, error)

NewClientWithContext 带上下文的客户端创建函数

type ClientConfig

type ClientConfig struct {
	// Endpoint 服务端点
	Endpoint string

	// Project 项目名称
	Project string

	// Timeout 超时时间
	Timeout time.Duration

	// UseGRPC 是否使用 gRPC(默认 false,使用 HTTP)
	UseGRPC bool

	// Auth 认证信息
	Auth *AuthConfig
}

ClientConfig Feast 客户端配置

type ClientOption

type ClientOption func(*ClientConfig)

ClientOption Feast 客户端配置选项

func WithAuth

func WithAuth(auth *AuthConfig) ClientOption

WithAuth 配置选项:设置认证信息

func WithHTTP

func WithHTTP() ClientOption

WithHTTP 配置选项:使用 HTTP 客户端

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout 配置选项:设置超时时间

type DefaultClientFactory

type DefaultClientFactory struct{}

DefaultClientFactory 是默认的 Feast HTTP 客户端工厂。

func (*DefaultClientFactory) NewClient

func (f *DefaultClientFactory) NewClient(ctx context.Context, endpoint, project string, opts ...ClientOption) (Client, error)

NewClient 创建 Feast HTTP 客户端

type Feature

type Feature struct {
	// Name 特征名称,例如 "driver_hourly_stats:conv_rate"
	Name string

	// FeatureView 特征视图名称,例如 "driver_hourly_stats"
	FeatureView string

	// ValueType 特征值类型,例如 "FLOAT", "INT64", "STRING"
	ValueType string

	// Description 特征描述
	Description string
}

Feature 特征定义

type FeatureMapping

type FeatureMapping struct {
	// UserFeatures 用户特征列表,例如 ["user_stats:age", "user_stats:gender"]
	UserFeatures []string

	// ItemFeatures 物品特征列表,例如 ["item_stats:price", "item_stats:category"]
	ItemFeatures []string

	// RealtimeFeatures 实时特征列表,例如 ["interaction:click_count", "interaction:view_count"]
	RealtimeFeatures []string

	// UserEntityKey 用户实体键名,默认 "user_id"
	UserEntityKey string

	// ItemEntityKey 物品实体键名,默认 "item_id"
	ItemEntityKey string
}

FeatureMapping 特征映射配置

type FeatureServiceAdapter

type FeatureServiceAdapter struct {
	// contains filtered or unexported fields
}

FeatureServiceAdapter 将 Feast Client 适配为 core.FeatureService 接口。

注意:此实现位于扩展包中,需要单独引入:

go get github.com/rushteam/reckit/ext/feast/http

这是推荐的使用方式:通过适配器将 Feast(基础设施层)适配为 core.FeatureService(领域层)。

func NewFeatureServiceAdapter

func NewFeatureServiceAdapter(client Client, mapping *FeatureMapping) *FeatureServiceAdapter

NewFeatureServiceAdapter 创建一个新的 FeatureService 适配器。

参数:

  • client: Feast 客户端(基础设施层)
  • mapping: 特征映射配置

返回:

  • *FeatureServiceAdapter: 实现了 core.FeatureService 接口的适配器

func (*FeatureServiceAdapter) BatchGetItemFeatures

func (a *FeatureServiceAdapter) BatchGetItemFeatures(ctx context.Context, itemIDs []string) (map[string]map[string]float64, error)

BatchGetItemFeatures 批量获取物品特征

func (*FeatureServiceAdapter) BatchGetRealtimeFeatures

func (a *FeatureServiceAdapter) BatchGetRealtimeFeatures(ctx context.Context, pairs []core.FeatureUserItemPair) (map[core.FeatureUserItemPair]map[string]float64, error)

BatchGetRealtimeFeatures 批量获取实时特征

func (*FeatureServiceAdapter) BatchGetUserFeatures

func (a *FeatureServiceAdapter) BatchGetUserFeatures(ctx context.Context, userIDs []string) (map[string]map[string]float64, error)

BatchGetUserFeatures 批量获取用户特征

func (*FeatureServiceAdapter) Close

Close 关闭特征服务(实现 core.FeatureService 接口)

func (*FeatureServiceAdapter) GetItemFeatures

func (a *FeatureServiceAdapter) GetItemFeatures(ctx context.Context, itemID string) (map[string]float64, error)

GetItemFeatures 获取物品特征

func (*FeatureServiceAdapter) GetRealtimeFeatures

func (a *FeatureServiceAdapter) GetRealtimeFeatures(ctx context.Context, userID, itemID string) (map[string]float64, error)

GetRealtimeFeatures 获取实时特征

func (*FeatureServiceAdapter) GetUserFeatures

func (a *FeatureServiceAdapter) GetUserFeatures(ctx context.Context, userID string) (map[string]float64, error)

GetUserFeatures 获取用户特征

func (*FeatureServiceAdapter) Name

func (a *FeatureServiceAdapter) Name() string

Name 返回特征服务名称

type FeatureServiceInfo

type FeatureServiceInfo struct {
	// Endpoint 服务端点
	Endpoint string

	// Project 项目名称
	Project string

	// FeatureViews 特征视图列表
	FeatureViews []string

	// OnlineStore 在线存储类型
	OnlineStore string

	// OfflineStore 离线存储类型
	OfflineStore string
}

FeatureServiceInfo 特征服务信息

type FeatureVector

type FeatureVector struct {
	// Values 特征值,key 为特征名称,value 为特征值
	Values map[string]interface{}

	// EntityRow 对应的实体行
	EntityRow map[string]interface{}
}

FeatureVector 特征向量

type GetHistoricalFeaturesRequest

type GetHistoricalFeaturesRequest struct {
	// EntityDF 实体数据框(包含实体 ID 和时间戳)
	EntityDF []map[string]interface{}

	// Features 特征名称列表
	Features []string

	// StartTime 开始时间(可选)
	StartTime *time.Time

	// EndTime 结束时间(可选)
	EndTime *time.Time

	// Project 项目名称(可选)
	Project string
}

GetHistoricalFeaturesRequest 获取历史特征请求

type GetHistoricalFeaturesResponse

type GetHistoricalFeaturesResponse struct {
	// DataFrame 历史特征数据框
	DataFrame []map[string]interface{}

	// Metadata 元数据
	Metadata map[string]interface{}
}

GetHistoricalFeaturesResponse 获取历史特征响应

type GetOnlineFeaturesRequest

type GetOnlineFeaturesRequest struct {
	// Features 特征名称列表,例如 ["driver_hourly_stats:conv_rate", "driver_hourly_stats:acc_rate"]
	Features []string

	// EntityRows 实体行,例如 [{"driver_id": 1001}, {"driver_id": 1002}]
	EntityRows []map[string]interface{}

	// Project 项目名称(可选)
	Project string
}

GetOnlineFeaturesRequest 获取在线特征请求

type GetOnlineFeaturesResponse

type GetOnlineFeaturesResponse struct {
	// FeatureVectors 特征向量列表,每个元素对应一个实体行
	FeatureVectors []FeatureVector

	// Metadata 元数据
	Metadata map[string]interface{}
}

GetOnlineFeaturesResponse 获取在线特征响应

type HTTPClient

type HTTPClient struct {
	// Endpoint 服务端点,例如 "http://localhost:6566"
	Endpoint string

	// Project 项目名称
	Project string

	// Timeout 超时时间
	Timeout time.Duration

	// Auth 认证信息
	Auth *AuthConfig
	// contains filtered or unexported fields
}

HTTPClient 是 Feast Feature Store 的 HTTP 客户端实现。

注意:此实现位于扩展包中,需要单独引入:

go get github.com/rushteam/reckit/ext/feast/http

func NewHTTPClient

func NewHTTPClient(endpoint, project string, opts ...ClientOption) (*HTTPClient, error)

NewHTTPClient 创建一个新的 Feast HTTP 客户端。

func (*HTTPClient) Close

func (c *HTTPClient) Close() error

Close 关闭连接(实现 Client 接口)

func (*HTTPClient) GetFeatureService

func (c *HTTPClient) GetFeatureService(ctx context.Context) (*FeatureServiceInfo, error)

GetFeatureService 获取特征服务信息

func (*HTTPClient) GetHistoricalFeatures

GetHistoricalFeatures 获取历史特征

func (*HTTPClient) GetOnlineFeatures

GetOnlineFeatures 获取在线特征

func (*HTTPClient) ListFeatures

func (c *HTTPClient) ListFeatures(ctx context.Context) ([]Feature, error)

ListFeatures 列出所有可用的特征

func (*HTTPClient) Materialize

func (c *HTTPClient) Materialize(ctx context.Context, req *MaterializeRequest) error

Materialize 将特征物化到在线存储

type MaterializeRequest

type MaterializeRequest struct {
	// StartTime 开始时间
	StartTime time.Time

	// EndTime 结束时间
	EndTime time.Time

	// FeatureViews 特征视图列表(可选,为空则物化所有)
	FeatureViews []string

	// Project 项目名称(可选)
	Project string
}

MaterializeRequest 物化请求

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL