chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package format
|
||||
|
||||
import sdk "academy/client"
|
||||
|
||||
// ReferenceIndex is the bounded citation pointer exposed by projected JSON,
|
||||
// text, and MCP output. ChunkID is the chunk the model cited; ParentChunkID is
|
||||
// retained when callers prefer to fetch the larger self-contained passage.
|
||||
// Full chunk text and retrieval metadata remain available only in raw NDJSON.
|
||||
type ReferenceIndex struct {
|
||||
KBID string `json:"kb_id,omitempty"`
|
||||
ChunkID string `json:"chunk_id"`
|
||||
ParentChunkID string `json:"parent_chunk_id,omitempty"`
|
||||
}
|
||||
|
||||
// IndexReferences projects full SDK search results into stable lookup keys.
|
||||
// It never mutates the SDK events, which keeps the raw NDJSON path lossless.
|
||||
// fallbackKBID is used by `chat`, whose single KB is known by the CLI even
|
||||
// when an older server omits knowledge_base_id from a reference.
|
||||
func IndexReferences(refs []*sdk.SearchResult, fallbackKBID string) []ReferenceIndex {
|
||||
indexes := make([]ReferenceIndex, 0, len(refs))
|
||||
for _, r := range refs {
|
||||
if r == nil || r.ID == "" {
|
||||
continue
|
||||
}
|
||||
kbID := r.KnowledgeBaseID
|
||||
if kbID == "" {
|
||||
kbID = fallbackKBID
|
||||
}
|
||||
indexes = append(indexes, ReferenceIndex{
|
||||
KBID: kbID,
|
||||
ChunkID: r.ID,
|
||||
ParentChunkID: r.ParentChunkID,
|
||||
})
|
||||
}
|
||||
return indexes
|
||||
}
|
||||
Reference in new issue
Block a user