sources

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

概述

Package sources 提供 RAG 外部知识源适配器,用于从第三方平台获取结构化数据 并转换为 RAG 管线可消费的格式。

每个 Source 封装了对应平台的 API 调用、重试逻辑和响应解析, 返回强类型的结果结构体,可通过 loader 包的 Adapter 转换为 rag.Document。

核心接口/类型

  • ArxivSource — arXiv 论文搜索适配器,解析 Atom XML 响应
  • ArxivPaper — arXiv 论文结构体(标题、摘要、作者、分类、PDF 链接等)
  • GitHubSource — GitHub 仓库和代码搜索适配器,支持 Token 认证
  • GitHubRepo — GitHub 仓库结构体(名称、描述、Stars、语言、Topics 等)
  • GitHubCodeResult — GitHub 代码搜索结果

主要能力

  • arXiv 论文搜索:按关键词和分类检索,支持排序、分页和自动重试
  • GitHub 仓库搜索:按关键词检索仓库,支持 Stars 和语言过滤
  • GitHub 代码搜索:按关键词和语言检索代码片段
  • GitHub README 获取:拉取指定仓库的 README 原始内容
  • 所有 HTTP 请求均使用 tlsutil.SecureHTTPClient 保障传输安全

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArxivConfig

type ArxivConfig struct {
	BaseURL    string        `json:"base_url"`    // arXiv API base URL
	MaxResults int           `json:"max_results"` // Maximum results per query
	SortBy     string        `json:"sort_by"`     // "relevance", "lastUpdatedDate", "submittedDate"
	SortOrder  string        `json:"sort_order"`  // "ascending", "descending"
	Timeout    time.Duration `json:"timeout"`     // HTTP request timeout
	RetryCount int           `json:"retry_count"` // Number of retries on failure
	RetryDelay time.Duration `json:"retry_delay"` // Delay between retries
	Categories []string      `json:"categories"`  // Filter by arXiv categories (e.g., "cs.AI", "cs.CL")
}

ArxivConfig配置了arXiv数据源适配器.

func DefaultArxivConfig

func DefaultArxivConfig() ArxivConfig

默认 ArxivConfig 返回 arXiv 查询的合理默认值 。

type ArxivPaper

type ArxivPaper struct {
	ID          string    `json:"id"`
	Title       string    `json:"title"`
	Summary     string    `json:"summary"`
	Authors     []string  `json:"authors"`
	Categories  []string  `json:"categories"`
	Published   time.Time `json:"published"`
	Updated     time.Time `json:"updated"`
	PDFURL      string    `json:"pdf_url"`
	AbstractURL string    `json:"abstract_url"`
	DOI         string    `json:"doi,omitempty"`
	Comment     string    `json:"comment,omitempty"`
}

ArxivPaper代表了ArXiv的论文.

type ArxivSource

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

Arxiv Source提供对arXiv文件的访问,供RAG检索.

func NewArxivSource

func NewArxivSource(config ArxivConfig, logger *zap.Logger) *ArxivSource

NewArxiv Source创建了新的arXiv数据源适配器.

func (*ArxivSource) Name

func (a *ArxivSource) Name() string

名称返回数据源名称 。

func (*ArxivSource) Search

func (a *ArxivSource) Search(ctx context.Context, query string, maxResults int) ([]ArxivPaper, error)

搜索匹配给定查询的文件 arXiv 。

func (*ArxivSource) ToJSON

func (a *ArxivSource) ToJSON(papers []ArxivPaper) (string, error)

ToJSON将论文串行到JSON调试/博客.

type GitHubCodeResult

type GitHubCodeResult struct {
	Name       string `json:"name"`
	Path       string `json:"path"`
	HTMLURL    string `json:"html_url"`
	Repository struct {
		FullName    string `json:"full_name"`
		Description string `json:"description"`
		HTMLURL     string `json:"html_url"`
	} `json:"repository"`
	Score float64 `json:"score"`
}

GitHubCodeResult代表了由GitHub生成的代码搜索结果.

type GitHubConfig

type GitHubConfig struct {
	BaseURL    string        `json:"base_url"`    // GitHub API base URL
	Token      string        `json:"-"`           // GitHub personal access token (not serialized)
	MaxResults int           `json:"max_results"` // Maximum results per query
	Timeout    time.Duration `json:"timeout"`     // HTTP request timeout
	RetryCount int           `json:"retry_count"` // Number of retries on failure
	RetryDelay time.Duration `json:"retry_delay"` // Delay between retries
}

GitHubConfig 配置了 GitHub 数据源适配器.

func DefaultGitHubConfig

func DefaultGitHubConfig() GitHubConfig

GitHubConfig 返回 GitHub 查询的合理默认值 。

type GitHubRepo

type GitHubRepo struct {
	FullName    string    `json:"full_name"`
	Description string    `json:"description"`
	URL         string    `json:"html_url"`
	Stars       int       `json:"stargazers_count"`
	Forks       int       `json:"forks_count"`
	Language    string    `json:"language"`
	Topics      []string  `json:"topics"`
	UpdatedAt   time.Time `json:"updated_at"`
	License     string    `json:"license_name,omitempty"`
	OpenIssues  int       `json:"open_issues_count"`
	ReadmeURL   string    `json:"readme_url,omitempty"`
}

GitHubRepo代表一个GitHub寄存器.

func FilterByLanguage

func FilterByLanguage(repos []GitHubRepo, language string) []GitHubRepo

FilterByLanguage过滤器通过编程语言重置.

func FilterByStars

func FilterByStars(repos []GitHubRepo, minStars int) []GitHubRepo

FilterByStars 过滤器通过最小星数重置.

type GitHubSearchResponse

type GitHubSearchResponse struct {
	TotalCount int          `json:"total_count"`
	Items      []GitHubRepo `json:"items"`
}

GitHubSearchResponse代表了GitHub搜索API响应.

type GitHubSource

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

GitHub Source提供对GitHub寄存器的访问,供RAG检索.

func NewGitHubSource

func NewGitHubSource(config GitHubConfig, logger *zap.Logger) *GitHubSource

NewGitHub Source创建了新的GitHub数据源适配器.

func (*GitHubSource) GetReadme

func (g *GitHubSource) GetReadme(ctx context.Context, owner, repo string) (string, error)

GetReadme 为仓库获取 README 内容 。

func (*GitHubSource) Name

func (g *GitHubSource) Name() string

名称返回数据源名称 。

func (*GitHubSource) SearchCode

func (g *GitHubSource) SearchCode(ctx context.Context, query string, language string, maxResults int) ([]GitHubCodeResult, error)

搜索代码搜索 GitHub 以匹配查询代码 。

func (*GitHubSource) SearchRepos

func (g *GitHubSource) SearchRepos(ctx context.Context, query string, maxResults int) ([]GitHubRepo, error)

SearchRepos 搜索匹配查询的 GitHub 寄存器 。

Jump to

Keyboard shortcuts

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