
🚜 开发中
Voy正在积极开发中。因此,API尚不稳定。请注意,在即将发布的1.0版本之前可能会有破坏性更改。
以下是我们正在进行的工作预览:
- WebAssembly中内置文本转换:目前,voy依赖于JavaScript库(如
transformers.js)来生成文本嵌入。详情请参阅使用方法。- 索引更新:当前在资源更新时需要重建索引。
- TypeScript支持:由于WASM工具的限制,复杂数据类型无法自动生成。
# 使用npm npm i voy-search # 使用Yarn yarn add voy-search # 使用pnpm pnpm add voy-search
class VoyVoy类封装了一个索引,并公开了Voy提供的所有公共方法。
class Voy { /** * 通过实例化一个资源,Voy将构建索引。如果资源不存在, * 它将构建一个空索引。稍后调用Voy.index()将覆盖空索引。 * @param {Resource | undefined} resource */ constructor(resource?: Resource); /** * 索引给定资源。Voy.index()设计用于在没有资源的情况下实例化Voy实例的场景。 * 它将覆盖现有索引。如果您想保留现有索引,可以使用Voy.add()将资源添加到索引中。 * @param {Resource} resource */ index(resource: Resource): void; /** * 使用给定的查询嵌入搜索前k个结果。 * @param {Float32Array} query: 查询嵌入 * @param {number} k: 搜索结果中的项目数 * @returns {SearchResult} */ search(query: Float32Array, k: number): SearchResult; /** * 将给定资源添加到索引中。 * @param {Resource} resource */ add(resource: Resource): void; /** * 从索引中移除给定资源。 * @param {Resource} resource */ remove(resource: Resource): void; /** * 从索引中移除所有资源。 */ clear(): void; /** * @returns {number} */ size(): number; /** * 序列化Voy实例。 * @returns {string} */ serialize(): string; /** * 将序列化的索引反序列化为Voy实例。 * @param {string} serialized_index * @returns {Voy} */ static deserialize(serialized_index: string): Voy; } interface Resource { embeddings: Array<{ id: string; // 资源的id title: string; // 资源的标题 url: string; // 资源的url embeddings: number[]; // 资源的嵌入 }>; } interface SearchResult { neighbors: Array<{ id: string; // 资源的id title: string; // 资源的标题 url: string; // 资源的url }>; }
除了Voy类,Voy还将所有实例方法作为独立函数导出。
index(resource: Resource): SerializedIndex它索引给定的资源并返回序列化的索引。
参数
interface Resource { embeddings: Array<{ id: string; // 资源的id title: string; // 资源的标题 url: string; // 资源的url embeddings: number[]; // 资源的嵌入 }>; }
返回值
type SerializedIndex = string;
search(index: SerializedIndex, query: Query, k: NumberOfResult): SearchResult它反序列化给定的索引并搜索查询的k个最近邻。
参数
type SerializedIndex = string; type Query = Float32Array; // 搜索查询的嵌入 type NumberOfResult = number; // 返回的K个顶部结果
返回值
interface SearchResult { neighbors: Array<{ id: string; // 资源的id title: string; // 资源的标题 url: string; // 资源的url }>; }
add(index: SerializedIndex, resource: Resource): SerializedIndex它将资源添加到索引中并返回更新后的序列化索引。
参数
type SerializedIndex = string; interface Resource { embeddings: Array<{ id: string; // 资源的id title: string; // 资源的标题 url: string; // 资源的url embeddings: number[]; // 资源的嵌入向量 }>; }
返回值
type SerializedIndex = string;
remove(index: SerializedIndex, resource: Resource): SerializedIndex它从索引中移除资源并返回更新后的序列化索引。
参数
type SerializedIndex = string; interface Resource { embeddings: Array<{ id: string; // 资源的id title: string; // 资源的标题 url: string; // 资源的url embeddings: number[]; // 资源的嵌入向量 }>; }
返回值
type SerializedIndex = string;
clear(index: SerializedIndex): SerializedIndex它从索引中移除所有项目并返回一个空的序列化索引。
参数
type SerializedIndex = string;
返回值
type SerializedIndex = string;
size(index: SerializedIndex): number;它返回索引的大小。
参数
type SerializedIndex = string;
目前,voy依赖于像transformers.js和web-ai这样的库来为文本生成嵌入向量:
import { TextModel } from "@visheratin/web-ai"; const { Voy } = await import("voy-search"); const phrases = [ "那是一个非常快乐的人", "那是一只快乐的狗", "今天是个阳光明媚的日子", ]; const query = "那是一个快乐的人"; // 创建文本嵌入 const model = await (await TextModel.create("gtr-t5-quant")).model; const processed = await Promise.all(phrases.map((q) => model.process(q))); // 使用voy为嵌入建立索引 const data = processed.map(({ result }, i) => ({ id: String(i), title: phrases[i], url: `/path/${i}`, embeddings: result, })); const resource = { embeddings: data }; const index = new Voy(resource); // 对查询嵌入进行相似度搜索 const q = await model.process(query); const result = index.search(q.result, 1); // 显示搜索结果 result.neighbors.forEach((result) => console.log(`✨ voy相似度搜索结果: "${result.title}"`) );
import { TextModel } from "@visheratin/web-ai"; const { Voy } = await import("voy-search"); const phrases = [ "那是一个非常快乐的人", "那是一只快乐的狗", "今天是个阳光明媚的日子", "向日葵正在盛开", ]; const model = await (await TextModel.create("gtr-t5-quant")).model; const processed = await Promise.all(phrases.map((q) => model.process(q))); const data = processed.map(({ result }, i) => ({ id: String(i), title: phrases[i], url: `/path/${i}`, embeddings: result, })); const resourceA = { embeddings: data.slice(0, 2) }; const resourceB = { embeddings: data.slice(2) }; const indexA = new Voy(resourceA); const indexB = new Voy(resourceB);
根据以下两种许可证之一授权
由您选择。
<a href="https://reflect.app" target="_blank"><img src="https://avatars.githubusercontent.com/u/73365487?s=64&v=4"></a> <a href="https://github.com/markhughes" target="_blank"><img src="https://avatars.githubusercontent.com/u/1357323?s=64&v=4"></a>
除非您明确声明,否则您有意提交以包含在作品中的任何贡献,如Apache-2.0许可证中所定义,均应按上述方式双重许可,无任何附加条款或条件。


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具


最适合小白的AI自动化工作流平台
无需编码,轻松生成可复用、可变现的AI自动化工作流

大模型驱动的Excel数据处理工具
基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


AI论文写作指导平台
AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。


企业专属的AI法律顾问
iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和 强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模型免费使用,一键生成无水印视频
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号