Documentation
¶
Overview ¶
Package fakeembed 是测试用的「假嵌入服务」:一个本机的 OpenAI 兼容 /embeddings 端点, 用确定性的「概念词典 + 字符 n-gram 哈希」造向量,使近义词在向量上相近、而词法完全不命中—— 这样才能验证「语义检索」真的比词法多找到了东西。它只被测试引用,不会进入任何生产代码路径。
Index ¶
- Variables
- type Options
- type Server
- func (s *Server) Auths() []string
- func (s *Server) BaseURL() string
- func (s *Server) Batches() [][]string
- func (s *Server) Embed(text string, dims int) []float32
- func (s *Server) FailWith(status, n int)
- func (s *Server) Inputs() []string
- func (s *Server) OverrideDimensions(d int)
- func (s *Server) RejectContaining(sub string)
- func (s *Server) Requests() int
- func (s *Server) Reset()
- func (s *Server) SetDelay(d time.Duration)
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultConcepts = [][]string{
{"汽车", "轿车", "机动车", "车辆", "car", "automobile", "vehicle"},
{"保养", "维修", "养护", "检修", "maintenance", "repair"},
{"数据库", "存储", "库表", "database", "storage"},
{"备份", "转储", "归档", "backup", "dump"},
{"登录", "鉴权", "认证", "login", "authentication"},
{"令牌", "凭证", "口令", "token", "credential"},
{"发布", "上线", "部署", "release", "deploy"},
{"回滚", "撤销", "还原", "rollback", "revert"},
{"会议", "评审", "讨论", "meeting", "review"},
{"预算", "费用", "成本", "budget", "cost"},
{"猫", "小猫", "猫咪", "cat", "kitten"},
{"狗", "小狗", "犬", "dog", "puppy"},
}
DefaultConcepts 是内置的概念词典:同一组里的词在向量上几乎一样(互为近义词)。
Functions ¶
This section is empty.
Types ¶
type Server ¶
Server 是一个假嵌入服务。
func (*Server) Embed ¶
Embed 是确定性的假嵌入:概念命中占据前 nConcept 维,字符 1-gram / 2-gram 带符号哈希占据其余维(权重很小)。 要求 dims > 概念数 + 8。
func (*Server) OverrideDimensions ¶
OverrideDimensions 让服务返回指定维度(模拟提供商悄悄换了维度);0 = 按请求。
func (*Server) RejectContaining ¶
RejectContaining 让「任何输入含 sub」的请求都以 400 应答(模拟内容安全拦截);空串 = 取消。
Click to show internal directories.
Click to hide internal directories.