Package storage.vdb
class FaissVectorStorage
func add
func add(doc: Document): Unit
func close
func close(): Unit
prop collection
prop collection: String
func commit
func commit(): Unit
prop embeddingModel
prop embeddingModel: EmbeddingModel
func init
init(embeddingModel: EmbeddingModel, workspace!: String = ".storage", collection!: String = "default")
- 描述: 初始化Faiss向量存储
- 参数:
embeddingModel: EmbeddingModel, 嵌入模型
workspace: String, 工作区路径
collection: String, 集合名称
func query
func query(query: String, topK: Int64, threshold!: Float64 = 0.6): Array<Document>
- 描述: 查询文档
- 参数:
query: String, 查询字符串
topK: Int64, 返回结果数量
threshold: Float64, 相似度阈值
func reset
func reset(): Unit
prop workspace
prop workspace: String
class JsonMemroyVectorStorage
func add
public func add(doc: Document): Unit
func close
public func close(): Unit
prop collection
public prop collection: String
func commit
public func commit(): Unit
prop embeddingModel
public prop embeddingModel: EmbeddingModel
func init
public init(embeddingModel: EmbeddingModel, workspace!: String = ".storage", collection!: String = "default")
- 描述: 初始化JsonMemroyVectorStorage实例
- 参数:
embeddingModel: EmbeddingModel, 用于生成嵌入向量的模型
workspace: String, 存储向量数据的目录路径,默认为".storage"
collection: String, 集合名称,默认为"default"
func query
public func query(query: String, topK: Int64, threshold!: Float64 = 0.6): Array<Document>
- 描述: 查询与输入字符串最相关的文档
- 参数:
query: String, 查询字符串
topK: Int64, 返回的最相关文档数量
threshold: Float64, 相似度阈值,默认为0.6
func queryWithScore
public func queryWithScore(query: String, topK: Int64, threshold!: Float64 = 0.6): Array<(Document, Float64)>
- 描述: 查询与输入字符串最相关的文档及其相似度分数
- 参数:
query: String, 查询字符串
topK: Int64, 返回的最相关文档数量
threshold: Float64, 相似度阈值,默认为0.6
func reset
public func reset(): Unit
prop workspace
public prop workspace: String
class LocalVectorStorage
interface VectorStorage
func add
func add(doc: Document): Unit
prop embeddingModel
prop embeddingModel: EmbeddingModel
func query
func query(query: String, topK: Int64, threshold!: Float64): Array<Document>
- 描述: 查询与输入字符串最相关的文档
- 参数:
query: String, 查询字符串
topK: Int64, 返回的文档数量上限
threshold!: Float64, 相似度阈值,低于此值的文档将被过滤
func queryWithScore
func queryWithScore(query: String, topK: Int64, threshold!: Float64): Array<(Document, Float64)>
- 描述: 查询与输入字符串最相关的文档,并返回相似度分数
- 参数:
query: String, 查询字符串
topK: Int64, 返回的文档数量上限
threshold!: Float64, 相似度阈值,低于此值的文档将被过滤