XU XUv0.16.0

#github.com/xulang-org/packages/rag

导入方式: rag #github.com/xulang-org/packages/rag

公开 API: 33 函数, 48 方法, 12 类型, 0 常量, 0 方法集

扩展包 `rag #github.com/xulang-org/packages/rag`,由模块 github.com/xulang-org/packages 提供。

github.com/xulang-org/packages · 1.17.2 · 安装与使用

struct Chunk

XuAPI
pub struct Chunk {
    pub id string
    pub doc_id string
    pub text string
    pub source string
    pub metadata_json string
    pub embedding []f32
}

用途

承载 id、doc_id、text、source、metadata_json 等属性的结构体。

公开字段

id string
字段(string)
doc_id string
字段(string)
text string
文本
source string
字段(string)
metadata_json string
字段(string)
embedding []f32
字段([]f32)

struct SearchHit

XuAPI
pub struct SearchHit {
    pub chunk Chunk
    pub score f64
}

用途

承载 chunk、score 等属性的结构体。

公开字段

chunk Chunk
字段(Chunk)
score f64
字段(f64)

struct MemoryStore

XuAPI
pub struct MemoryStore {
    pub dim int
    pub chunks []Chunk
}

用途

承载 dim、chunks 等属性的结构体。

公开字段

dim int
字段(int)
chunks []Chunk
字段([]Chunk)

struct ParentChildDoc

XuAPI
pub struct ParentChildDoc {
    pub parents []Chunk
    pub children []Chunk
}

用途

承载 parents、children 等属性的结构体。

公开字段

parents []Chunk
字段([]Chunk)
children []Chunk
字段([]Chunk)

new_store

XuAPI
pub fn new_store(dim int) MemoryStore

用途

构造 store。

参数

dim int
dim(int)

返回值

MemoryStore — 该类型的值

(&MemoryStore) len

XuAPI
pub fn (s &MemoryStore) len() int

用途

&MemoryStore 上的操作:返回长度。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

chunk_text

XuAPI
pub fn chunk_text(text string, chunk_size int, overlap int) []string

用途

执行 chunk text 操作。

参数

text string
文本(string)
chunk_size int
chunk_size(int)
overlap int
overlap(int)

返回值

[]string — 切片结果

chunk_recursive

XuAPI
pub fn chunk_recursive(text string, max_chars int, overlap int) []string

用途

执行 chunk recursive 操作。

参数

text string
文本(string)
max_chars int
max_chars(int)
overlap int
overlap(int)

返回值

[]string — 切片结果

($&MemoryStore) add_chunk

XuAPI
pub fn (s $&MemoryStore) add_chunk(id string, doc_id string, text string, source string, metadata_json string, embedding &[]f64) int

用途

$&MemoryStore 上的操作:执行 add chunk 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s $&MemoryStore
本次调用使用的 MemoryStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
id string
id(string)
doc_id string
doc_id(string)
text string
文本(string)
source string
source(string)
metadata_json string
metadata_json(string)
embedding &[]f64
embedding(只读借用,调用方仍持有原值;类型 &[]f64)

返回值

int — 该类型的值

(&MemoryStore) save_json

XuAPI
pub fn (s &MemoryStore) save_json(path string) int

用途

&MemoryStore 上的操作:执行 save json 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
path string
文件系统路径(string)

返回值

int — 该类型的值

load_json

XuAPI
pub fn load_json(path string) MemoryStore

用途

执行 load json 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path string
文件系统路径(string)

返回值

MemoryStore — 该类型的值

index_document

XuAPI
pub fn index_document(store $&MemoryStore, client &openai.Client, embed_model string, doc_id string, source string, text string, chunk_size int, overlap int, metadata_json string) int

用途

执行 index document 操作。失败时抛出错误,调用方需处理或继续传播。

参数

store $&MemoryStore
store(独占借用,可修改原值;类型 $&MemoryStore)
client &openai.Client
client(只读借用,调用方仍持有原值;类型 &openai.Client)
embed_model string
embed_model(string)
doc_id string
doc_id(string)
source string
source(string)
text string
文本(string)
chunk_size int
chunk_size(int)
overlap int
overlap(int)
metadata_json string
metadata_json(string)

返回值

int — 索引值;有效范围和特殊值见用途说明

retrieve

XuAPI
pub fn retrieve(store &MemoryStore, client &openai.Client, embed_model string, query string, top_k int, filter_doc_id string) []SearchHit

用途

执行 retrieve 处理。失败时抛出错误,调用方需处理或继续传播。

参数

store &MemoryStore
store(只读借用,调用方仍持有原值;类型 &MemoryStore)
client &openai.Client
client(只读借用,调用方仍持有原值;类型 &openai.Client)
embed_model string
embed_model(string)
query string
query(string)
top_k int
top_k(int)
filter_doc_id string
filter_doc_id(string)

返回值

[]SearchHit — 切片结果

format_context

XuAPI
pub fn format_context(hits &[]SearchHit) string

用途

格式化为 context。

参数

hits &[]SearchHit
hits(只读借用,调用方仍持有原值;类型 &[]SearchHit)

返回值

string — 结果字符串

chunk_markdown

XuAPI
pub fn chunk_markdown(doc_id string, source string, markdown string, max_chars int, overlap int) []Chunk

用途

执行 chunk markdown 操作。

参数

doc_id string
doc_id(string)
source string
source(string)
markdown string
markdown(string)
max_chars int
max_chars(int)
overlap int
overlap(int)

返回值

[]Chunk — 切片结果

(&MemoryStore) search_bm25_filtered

XuAPI
pub fn (s &MemoryStore) search_bm25_filtered(query string, top_k int, filter_doc_id string) []SearchHit

用途

&MemoryStore 上的操作:执行 search bm25 filtered 操作。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
query string
query(string)
top_k int
top_k(int)
filter_doc_id string
filter_doc_id(string)

返回值

[]SearchHit — 切片结果

(&MemoryStore) search_bm25

XuAPI
pub fn (s &MemoryStore) search_bm25(query string, top_k int) []SearchHit

用途

&MemoryStore 上的操作:二分查找bm25。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
query string
query(string)
top_k int
top_k(int)

返回值

[]SearchHit — 切片结果

(&MemoryStore) search_hybrid_filtered

XuAPI
pub fn (s &MemoryStore) search_hybrid_filtered(query string, query_emb &[]f64, top_k int, rrf_k int, filter_doc_id string) []SearchHit

用途

&MemoryStore 上的操作:执行 search hybrid filtered 操作。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
query string
query(string)
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
rrf_k int
rrf_k(int)
filter_doc_id string
filter_doc_id(string)

返回值

[]SearchHit — 切片结果

(&MemoryStore) search_hybrid

XuAPI
pub fn (s &MemoryStore) search_hybrid(query string, query_emb &[]f64, top_k int, rrf_k int) []SearchHit

用途

&MemoryStore 上的操作:执行 search hybrid 操作。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
query string
query(string)
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
rrf_k int
rrf_k(int)

返回值

[]SearchHit — 切片结果

(&MemoryStore) retrieve_hybrid

XuAPI
pub fn (s &MemoryStore) retrieve_hybrid(query string, query_emb &[]f64, top_k int, rrf_k int) string

用途

&MemoryStore 上的操作:执行 retrieve hybrid 操作。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
query string
query(string)
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
rrf_k int
rrf_k(int)

返回值

string — 结果字符串

(&MemoryStore) search_mmr

XuAPI
pub fn (s &MemoryStore) search_mmr(query_emb &[]f64, top_k int, lambda f64, filter_doc_id string) []SearchHit

用途

&MemoryStore 上的操作:执行 search mmr 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
lambda f64
lambda(f64)
filter_doc_id string
filter_doc_id(string)

返回值

[]SearchHit — 切片结果

($&MemoryStore) delete_doc

XuAPI
pub fn (s $&MemoryStore) delete_doc(doc_id string) int

用途

$&MemoryStore 上的操作:执行 delete doc 操作。

参数

s $&MemoryStore
本次调用使用的 MemoryStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
doc_id string
doc_id(string)

返回值

int — 该类型的值

(&MemoryStore) search_by_meta

XuAPI
pub fn (s &MemoryStore) search_by_meta(query_emb &[]f64, top_k int, filter_doc_id string, meta_key string, meta_val string) []SearchHit

用途

&MemoryStore 上的操作:执行 search by meta 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
filter_doc_id string
filter_doc_id(string)
meta_key string
meta_key(string)
meta_val string
meta_val(string)

返回值

[]SearchHit — 切片结果

(&MemoryStore) search_hybrid_by_meta

XuAPI
pub fn (s &MemoryStore) search_hybrid_by_meta(query string, query_emb &[]f64, top_k int, rrf_k int, filter_doc_id string, meta_key string, meta_val string) []SearchHit

用途

&MemoryStore 上的操作:执行 search hybrid by meta 操作。

参数

s &MemoryStore
本次调用使用的 MemoryStore 实例;以只读借用传入,调用方仍持有实例。
query string
query(string)
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
rrf_k int
rrf_k(int)
filter_doc_id string
filter_doc_id(string)
meta_key string
meta_key(string)
meta_val string
meta_val(string)

返回值

[]SearchHit — 切片结果

rerank_hits

XuAPI
pub fn rerank_hits(hits &[]SearchHit, scores &[]f64, top_k int) []SearchHit

用途

执行 rerank hits 操作。

参数

hits &[]SearchHit
hits(只读借用,调用方仍持有原值;类型 &[]SearchHit)
scores &[]f64
scores(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)

返回值

[]SearchHit — 切片结果

rerank_with_api

XuAPI
pub fn rerank_with_api(client &openai.Client, model string, query string, hits &[]SearchHit, top_k int) []SearchHit

用途

执行 rerank with api 操作。失败时抛出错误,调用方需处理或继续传播。

参数

client &openai.Client
client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string
model(string)
query string
query(string)
hits &[]SearchHit
hits(只读借用,调用方仍持有原值;类型 &[]SearchHit)
top_k int
top_k(int)

返回值

[]SearchHit — 切片结果

chunk_parent_child

XuAPI
pub fn chunk_parent_child(doc_id string, source string, text string, parent_chars int, child_chars int, overlap int) ParentChildDoc

用途

执行 chunk parent child 操作。

参数

doc_id string
doc_id(string)
source string
source(string)
text string
文本(string)
parent_chars int
parent_chars(int)
child_chars int
child_chars(int)
overlap int
overlap(int)

返回值

ParentChildDoc — 该类型的值

expand_to_parents

XuAPI
pub fn expand_to_parents(child_hits &[]SearchHit, parents &[]Chunk) []SearchHit

用途

执行 expand to parents 操作。

参数

child_hits &[]SearchHit
child_hits(只读借用,调用方仍持有原值;类型 &[]SearchHit)
parents &[]Chunk
parents(只读借用,调用方仍持有原值;类型 &[]Chunk)

返回值

[]SearchHit — 切片结果

expand_queries_openai

XuAPI
pub fn expand_queries_openai(client &openai.Client, model string, query string, n int) []string

用途

执行 expand queries openai 操作。失败时抛出错误,调用方需处理或继续传播。

参数

client &openai.Client
client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string
model(string)
query string
query(string)
n int
数量、长度或上限(int)

返回值

[]string — 切片结果

hyde_document_openai

XuAPI
pub fn hyde_document_openai(client &openai.Client, model string, query string) string

用途

执行 hyde document openai 操作。失败时抛出错误,调用方需处理或继续传播。

参数

client &openai.Client
client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string
model(string)
query string
query(string)

返回值

string — 结果字符串

compress_context

XuAPI
pub fn compress_context(query &string, hits &[]SearchHit, max_sentences_per_hit int) []SearchHit

用途

压缩上下文。

参数

query &string
query(只读借用,调用方仍持有原值;类型 &string)
hits &[]SearchHit
hits(只读借用,调用方仍持有原值;类型 &[]SearchHit)
max_sentences_per_hit int
max_sentences_per_hit(int)

返回值

[]SearchHit — 切片结果

format_context_cited

XuAPI
pub fn format_context_cited(hits &[]SearchHit) string

用途

格式化为 context cited。

参数

hits &[]SearchHit
hits(只读借用,调用方仍持有原值;类型 &[]SearchHit)

返回值

string — 结果字符串

struct PgVectorStore

XuAPI
pub struct PgVectorStore {
    pub table string
    pub dim int
    pub metric string
}

用途

承载 table、dim、metric 等属性的结构体。

公开字段

table string
字段(string)
dim int
字段(int)
metric string
字段(string)

new_pgvector_store

XuAPI
pub fn new_pgvector_store(table string, dim int, metric string) PgVectorStore

用途

构造 pgvector store。失败时抛出错误,调用方需处理或继续传播。

参数

table string
table(string)
dim int
dim(int)
metric string
metric(string)

返回值

PgVectorStore — 该类型的值

(&PgVectorStore) create_table_sql

XuAPI
pub fn (s &PgVectorStore) create_table_sql() string

用途

&PgVectorStore 上的操作:执行 create table sql 操作。

参数

s &PgVectorStore
本次调用使用的 PgVectorStore 实例;以只读借用传入,调用方仍持有实例。

返回值

string — 结果字符串

(&PgVectorStore) create_index_sql

XuAPI
pub fn (s &PgVectorStore) create_index_sql(index_name string, method string) string

用途

&PgVectorStore 上的操作:执行 create index sql 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s &PgVectorStore
本次调用使用的 PgVectorStore 实例;以只读借用传入,调用方仍持有实例。
index_name string
index_name(string)
method string
method(string)

返回值

string — 结果字符串

(&PgVectorStore) upsert_chunk_sql

XuAPI
pub fn (s &PgVectorStore) upsert_chunk_sql(c &Chunk) string

用途

&PgVectorStore 上的操作:执行 upsert chunk sql 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s &PgVectorStore
本次调用使用的 PgVectorStore 实例;以只读借用传入,调用方仍持有实例。
c &Chunk
字节或字符码(只读借用,调用方仍持有原值;类型 &Chunk)

返回值

string — 结果字符串

(&PgVectorStore) search_sql

XuAPI
pub fn (s &PgVectorStore) search_sql(query_emb &[]f64, top_k int, filter_doc_id string) string

用途

&PgVectorStore 上的操作:执行 search sql 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s &PgVectorStore
本次调用使用的 PgVectorStore 实例;以只读借用传入,调用方仍持有实例。
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
filter_doc_id string
filter_doc_id(string)

返回值

string — 结果字符串

chunk_code

XuAPI
pub fn chunk_code(code string, max_chars int, overlap int) []string

用途

执行 chunk code 操作。

参数

code string
码(string)
max_chars int
max_chars(int)
overlap int
overlap(int)

返回值

[]string — 切片结果

rerank_with_cohere

XuAPI
pub fn rerank_with_cohere(client &cohere.Client, model string, query string, hits &[]SearchHit, top_k int) []SearchHit

用途

执行 rerank with cohere 操作。失败时抛出错误,调用方需处理或继续传播。

参数

client &cohere.Client
client(只读借用,调用方仍持有原值;类型 &cohere.Client)
model string
model(string)
query string
query(string)
hits &[]SearchHit
hits(只读借用,调用方仍持有原值;类型 &[]SearchHit)
top_k int
top_k(int)

返回值

[]SearchHit — 切片结果

struct Triple

XuAPI
pub struct Triple {
    pub subject string
    pub predicate string
    pub object string
    pub source string
}

用途

承载 subject、predicate、object、source 等属性的结构体。

公开字段

subject string
字段(string)
predicate string
字段(string)
object string
字段(string)
source string
字段(string)

struct KnowledgeGraph

XuAPI
pub struct KnowledgeGraph {
    pub triples []Triple
}

用途

承载 triples 等属性的结构体。

公开字段

triples []Triple
字段([]Triple)

new_knowledge_graph

XuAPI
pub fn new_knowledge_graph() KnowledgeGraph

用途

构造 knowledge graph。

参数

无需传入参数。

返回值

KnowledgeGraph — 该类型的值

(&KnowledgeGraph) len

XuAPI
pub fn (kg &KnowledgeGraph) len() int

用途

&KnowledgeGraph 上的操作:返回长度。

参数

kg &KnowledgeGraph
本次调用使用的 KnowledgeGraph 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

($&KnowledgeGraph) add_triple

XuAPI
pub fn (kg $&KnowledgeGraph) add_triple(subject string, predicate string, object string, source string)

用途

$&KnowledgeGraph 上的操作:执行 add triple 操作。

参数

kg $&KnowledgeGraph
本次调用使用的 KnowledgeGraph 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
subject string
subject(string)
predicate string
predicate(string)
object string
object(string)
source string
source(string)

返回值

不返回值。

(&KnowledgeGraph) query_neighbors

XuAPI
pub fn (kg &KnowledgeGraph) query_neighbors(entity string, max_hops int) []Triple

用途

&KnowledgeGraph 上的操作:执行 query neighbors 操作。

参数

kg &KnowledgeGraph
本次调用使用的 KnowledgeGraph 实例;以只读借用传入,调用方仍持有实例。
entity string
entity(string)
max_hops int
max_hops(int)

返回值

[]Triple — 切片结果

format_subgraph

XuAPI
pub fn format_subgraph(triples &[]Triple) string

用途

格式化为 subgraph。

参数

triples &[]Triple
triples(只读借用,调用方仍持有原值;类型 &[]Triple)

返回值

string — 结果字符串

(&KnowledgeGraph) save_json

XuAPI
pub fn (kg &KnowledgeGraph) save_json(path string) int

用途

&KnowledgeGraph 上的操作:执行 save json 操作。失败时抛出错误,调用方需处理或继续传播。

参数

kg &KnowledgeGraph
本次调用使用的 KnowledgeGraph 实例;以只读借用传入,调用方仍持有实例。
path string
文件系统路径(string)

返回值

int — 该类型的值

load_knowledge_graph_json

XuAPI
pub fn load_knowledge_graph_json(path string) KnowledgeGraph

用途

执行 load knowledge graph json 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path string
文件系统路径(string)

返回值

KnowledgeGraph — 该类型的值

contextualize_chunks_openai

XuAPI
pub fn contextualize_chunks_openai(client &openai.Client, model string, doc_title string, full_doc_summary string, chunks &[]string) []string

用途

执行 contextualize chunks openai 操作。失败时抛出错误,调用方需处理或继续传播。

参数

client &openai.Client
client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string
model(string)
doc_title string
doc_title(string)
full_doc_summary string
full_doc_summary(string)
chunks &[]string
chunks(只读借用,调用方仍持有原值;类型 &[]string)

返回值

[]string — 切片结果

struct HybridGraphResult

XuAPI
pub struct HybridGraphResult {
    pub hits []SearchHit
    pub graph_triples []Triple
    pub formatted_context string
}

用途

承载 hits、graph_triples、formatted_context 等属性的结构体。

公开字段

hits []SearchHit
字段([]SearchHit)
graph_triples []Triple
字段([]Triple)
formatted_context string
字段(string)

struct PgVectorClient

XuAPI
pub struct PgVectorClient {
    pub store PgVectorStore
}

用途

Rag 客户端会话实例,维护与服务端的连接并提供操作接口。

公开字段

store PgVectorStore
字段(PgVectorStore)

new_pgvector_client

XuAPI
pub fn new_pgvector_client(conn driver.Conn, table string, dim int, metric string) PgVectorClient

用途

构造 pgvector client。失败时抛出错误,调用方需处理或继续传播。

参数

conn driver.Conn
conn(driver.Conn)
table string
table(string)
dim int
dim(int)
metric string
metric(string)

返回值

PgVectorClient — 该类型的值

open_pgvector_client

XuAPI
pub fn open_pgvector_client(dsn string, table string, dim int, metric string) PgVectorClient

用途

执行 open pgvector client 操作。失败时抛出错误,调用方需处理或继续传播。

参数

dsn string
dsn(string)
table string
table(string)
dim int
dim(int)
metric string
metric(string)

返回值

PgVectorClient — 该类型的值

($&PgVectorClient) ensure_table

XuAPI
pub fn (c $&PgVectorClient) ensure_table() int

用途

$&PgVectorClient 上的操作:执行 ensure table 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&PgVectorClient
本次调用使用的 PgVectorClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&PgVectorClient) ensure_index

XuAPI
pub fn (c $&PgVectorClient) ensure_index(index_name string, method string) int

用途

$&PgVectorClient 上的操作:执行 ensure index 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&PgVectorClient
本次调用使用的 PgVectorClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
index_name string
index_name(string)
method string
method(string)

返回值

int — 索引值;有效范围和特殊值见用途说明

($&PgVectorClient) upsert_chunk

XuAPI
pub fn (c $&PgVectorClient) upsert_chunk(ch &Chunk) int

用途

$&PgVectorClient 上的操作:执行 upsert chunk 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&PgVectorClient
本次调用使用的 PgVectorClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
ch &Chunk
字符码(只读借用,调用方仍持有原值;类型 &Chunk)

返回值

int — 该类型的值

($&PgVectorClient) delete_doc

XuAPI
pub fn (c $&PgVectorClient) delete_doc(doc_id string) int

用途

$&PgVectorClient 上的操作:执行 delete doc 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&PgVectorClient
本次调用使用的 PgVectorClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
doc_id string
doc_id(string)

返回值

int — 该类型的值

($&PgVectorClient) close

XuAPI
pub fn (c $&PgVectorClient) close() int

用途

$&PgVectorClient 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

c $&PgVectorClient
本次调用使用的 PgVectorClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

struct PgVectorPool

XuAPI
pub struct PgVectorPool {
    pub store PgVectorStore
}

用途

Rag 连接池管理器,并发安全地维护和调度复用套接字连接。

公开字段

store PgVectorStore
字段(PgVectorStore)

new_pgvector_pool

XuAPI
pub fn new_pgvector_pool(db sql.DB, table string, dim int, metric string) PgVectorPool

用途

构造 pgvector pool。失败时抛出错误,调用方需处理或继续传播。

参数

db sql.DB
db(sql.DB)
table string
table(string)
dim int
dim(int)
metric string
metric(string)

返回值

PgVectorPool — 该类型的值

open_pgvector_pool

XuAPI
pub fn open_pgvector_pool(dsn string, table string, dim int, metric string, max_open int, max_idle int) PgVectorPool

用途

执行 open pgvector pool 操作。失败时抛出错误,调用方需处理或继续传播。

参数

dsn string
dsn(string)
table string
table(string)
dim int
dim(int)
metric string
metric(string)
max_open int
max_open(int)
max_idle int
max_idle(int)

返回值

PgVectorPool — 该类型的值

(&PgVectorPool) ensure_table

XuAPI
pub fn (p &PgVectorPool) ensure_table() int

用途

&PgVectorPool 上的操作:执行 ensure table 操作。失败时抛出错误,调用方需处理或继续传播。

参数

p &PgVectorPool
本次调用使用的 PgVectorPool 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&PgVectorPool) ensure_index

XuAPI
pub fn (p &PgVectorPool) ensure_index(index_name string, method string) int

用途

&PgVectorPool 上的操作:执行 ensure index 操作。失败时抛出错误,调用方需处理或继续传播。

参数

p &PgVectorPool
本次调用使用的 PgVectorPool 实例;以只读借用传入,调用方仍持有实例。
index_name string
index_name(string)
method string
method(string)

返回值

int — 索引值;有效范围和特殊值见用途说明

(&PgVectorPool) upsert_chunk

XuAPI
pub fn (p &PgVectorPool) upsert_chunk(ch &Chunk) int

用途

&PgVectorPool 上的操作:执行 upsert chunk 操作。失败时抛出错误,调用方需处理或继续传播。

参数

p &PgVectorPool
本次调用使用的 PgVectorPool 实例;以只读借用传入,调用方仍持有实例。
ch &Chunk
字符码(只读借用,调用方仍持有原值;类型 &Chunk)

返回值

int — 该类型的值

(&PgVectorPool) delete_doc

XuAPI
pub fn (p &PgVectorPool) delete_doc(doc_id string) int

用途

&PgVectorPool 上的操作:执行 delete doc 操作。失败时抛出错误,调用方需处理或继续传播。

参数

p &PgVectorPool
本次调用使用的 PgVectorPool 实例;以只读借用传入,调用方仍持有实例。
doc_id string
doc_id(string)

返回值

int — 该类型的值

($&PgVectorPool) close

XuAPI
pub fn (p $&PgVectorPool) close() int

用途

$&PgVectorPool 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

p $&PgVectorPool
本次调用使用的 PgVectorPool 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

struct SqliteVectorStore

XuAPI
pub struct SqliteVectorStore {
    pub table string
    pub dim int
}

用途

承载 table、dim 等属性的结构体。

公开字段

table string
字段(string)
dim int
字段(int)

new_sqlite_store

XuAPI
pub fn new_sqlite_store(conn driver.Conn, table string, dim int) SqliteVectorStore

用途

构造 sqlite store。失败时抛出错误,调用方需处理或继续传播。

参数

conn driver.Conn
conn(driver.Conn)
table string
table(string)
dim int
dim(int)

返回值

SqliteVectorStore — 该类型的值

open_sqlite_store

XuAPI
pub fn open_sqlite_store(path string, table string, dim int) SqliteVectorStore

用途

执行 open sqlite store 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path string
文件系统路径(string)
table string
table(string)
dim int
dim(int)

返回值

SqliteVectorStore — 该类型的值

($&SqliteVectorStore) upsert_chunk

XuAPI
pub fn (s $&SqliteVectorStore) upsert_chunk(c &Chunk) int

用途

$&SqliteVectorStore 上的操作:执行 upsert chunk 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s $&SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
c &Chunk
字节或字符码(只读借用,调用方仍持有原值;类型 &Chunk)

返回值

int — 该类型的值

($&SqliteVectorStore) add_chunk

XuAPI
pub fn (s $&SqliteVectorStore) add_chunk(id string, doc_id string, text string, source string, metadata_json string, embedding &[]f64) int

用途

$&SqliteVectorStore 上的操作:执行 add chunk 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s $&SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
id string
id(string)
doc_id string
doc_id(string)
text string
文本(string)
source string
source(string)
metadata_json string
metadata_json(string)
embedding &[]f64
embedding(只读借用,调用方仍持有原值;类型 &[]f64)

返回值

int — 该类型的值

($&SqliteVectorStore) delete_doc

XuAPI
pub fn (s $&SqliteVectorStore) delete_doc(doc_id string) int

用途

$&SqliteVectorStore 上的操作:执行 delete doc 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s $&SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
doc_id string
doc_id(string)

返回值

int — 该类型的值

(&SqliteVectorStore) cached_len

XuAPI
pub fn (s &SqliteVectorStore) cached_len() int

用途

&SqliteVectorStore 上的操作:执行 cached len 操作。

参数

s &SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

($&SqliteVectorStore) refresh_cache

XuAPI
pub fn (s $&SqliteVectorStore) refresh_cache() int

用途

$&SqliteVectorStore 上的操作:执行 refresh cache 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s $&SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

(&SqliteVectorStore) count

XuAPI
pub fn (s &SqliteVectorStore) count() int

用途

&SqliteVectorStore 上的操作:统计非重叠出现次数。失败时抛出错误,调用方需处理或继续传播。

参数

s &SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&SqliteVectorStore) load_memory_store

XuAPI
pub fn (s &SqliteVectorStore) load_memory_store(filter_doc_id string) MemoryStore

用途

&SqliteVectorStore 上的操作:执行 load memory store 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s &SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以只读借用传入,调用方仍持有实例。
filter_doc_id string
filter_doc_id(string)

返回值

MemoryStore — 该类型的值

(&SqliteVectorStore) search_hybrid

XuAPI
pub fn (s &SqliteVectorStore) search_hybrid(query string, query_emb &[]f64, top_k int, rrf_k int, filter_doc_id string) []SearchHit

用途

&SqliteVectorStore 上的操作:执行 search hybrid 操作。

参数

s &SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以只读借用传入,调用方仍持有实例。
query string
query(string)
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
rrf_k int
rrf_k(int)
filter_doc_id string
filter_doc_id(string)

返回值

[]SearchHit — 切片结果

($&SqliteVectorStore) close

XuAPI
pub fn (s $&SqliteVectorStore) close() int

用途

$&SqliteVectorStore 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

s $&SqliteVectorStore
本次调用使用的 SqliteVectorStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

struct QdrantVectorStore

XuAPI
pub struct QdrantVectorStore {
    pub client qdrant.Client
    pub collection string
    pub dim int
}

用途

承载 client、collection、dim 等属性的结构体。

公开字段

client qdrant.Client
字段(qdrant.Client)
collection string
字段(string)
dim int
字段(int)

new_qdrant_store

XuAPI
pub fn new_qdrant_store(endpoint string, api_key string, collection string, dim int) QdrantVectorStore

用途

构造 qdrant store。失败时抛出错误,调用方需处理或继续传播。

参数

endpoint string
endpoint(string)
api_key string
api_key(string)
collection string
collection(string)
dim int
dim(int)

返回值

QdrantVectorStore — 该类型的值

($&QdrantVectorStore) ensure_collection

XuAPI
pub fn (s $&QdrantVectorStore) ensure_collection(distance string) bool

用途

$&QdrantVectorStore 上的操作:执行 ensure collection 操作。

参数

s $&QdrantVectorStore
本次调用使用的 QdrantVectorStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
distance string
distance(string)

返回值

bool — 是否成立

($&QdrantVectorStore) upsert_chunk

XuAPI
pub fn (s $&QdrantVectorStore) upsert_chunk(point_id int, c &Chunk) bool

用途

$&QdrantVectorStore 上的操作:执行 upsert chunk 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s $&QdrantVectorStore
本次调用使用的 QdrantVectorStore 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
point_id int
point_id(int)
c &Chunk
字节或字符码(只读借用,调用方仍持有原值;类型 &Chunk)

返回值

bool — 是否成立

extract_triples_openai

XuAPI
pub fn extract_triples_openai(client &openai.Client, model string, text string, source string) []Triple

用途

执行 extract triples openai 操作。失败时抛出错误,调用方需处理或继续传播。

参数

client &openai.Client
client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string
model(string)
text string
文本(string)
source string
source(string)

返回值

[]Triple — 切片结果

($&KnowledgeGraph) ingest_text_openai

XuAPI
pub fn (kg $&KnowledgeGraph) ingest_text_openai(client &openai.Client, model string, text string, source string) int

用途

$&KnowledgeGraph 上的操作:执行 ingest text openai 操作。失败时抛出错误,调用方需处理或继续传播。

参数

kg $&KnowledgeGraph
本次调用使用的 KnowledgeGraph 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
client &openai.Client
client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string
model(string)
text string
文本(string)
source string
source(string)

返回值

int — 该类型的值

(&KnowledgeGraph) match_entities

XuAPI
pub fn (kg &KnowledgeGraph) match_entities(text &string) []string

用途

&KnowledgeGraph 上的操作:执行 match entities 操作。

参数

kg &KnowledgeGraph
本次调用使用的 KnowledgeGraph 实例;以只读借用传入,调用方仍持有实例。
text &string
文本(只读借用,调用方仍持有原值;类型 &string)

返回值

[]string — 切片结果

hybrid_graph_vector_search_auto

XuAPI
pub fn hybrid_graph_vector_search_auto(store &MemoryStore, kg &KnowledgeGraph, query string, query_emb &[]f64, top_k int, graph_hops int) HybridGraphResult

用途

执行 hybrid graph vector search auto 操作。

参数

store &MemoryStore
store(只读借用,调用方仍持有原值;类型 &MemoryStore)
kg &KnowledgeGraph
kg(只读借用,调用方仍持有原值;类型 &KnowledgeGraph)
query string
query(string)
query_emb &[]f64
query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int
top_k(int)
graph_hops int
graph_hops(int)

返回值

HybridGraphResult — 该类型的值