惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Martin Fowler
Martin Fowler
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
O
OpenAI News
云风的 BLOG
云风的 BLOG
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
V
Vulnerabilities – Threatpost
P
Privacy & Cybersecurity Law Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
博客园 - 三生石上(FineUI控件)
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News | PayPal Newsroom
The Register - Security
The Register - Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cisco Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Vercel News
Vercel News
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
S
Security Affairs
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
T
Tor Project blog
大猫的无限游戏
大猫的无限游戏
L
Lohrmann on Cybersecurity
aimingoo的专栏
aimingoo的专栏
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 【当耐特】
V
V2EX
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LINUX DO - 最新话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
小众软件
小众软件
PCI Perspectives
PCI Perspectives

博客园 - 慕尘

在浏览器跑 Qwen2.5 使用 WSL 在 Windows 上安装 Linux LangExtract pgvector 向量数据库 Faiss Goose trafilatura unstructured python里使用Playwright python的jieba MinGW 解析非结构化数据 LangChain 的 DocumentLoader 能够使用require但不能使用import ChromaDB nvm-windows 使用js实现文字转语音 pyttsx3 Ollama笔记
nomic-embed-text
慕尘 · 2025-03-05 · via 博客园 - 慕尘

nomic-embed-text 是一个用于生成高质量文本嵌入(embeddings)的工具或模型

将文本转换为固定长度的向量表示,这些向量可以用于语义搜索、文本分类、聚类等任务

使用本地 ollama 部署的 nomic-embed-text

import { OllamaEmbeddings } from "@langchain/ollama";

const embeddings = new OllamaEmbeddings({
  model: "nomic-embed-text:latest",
  baseUrl: "http://192.168.0.220:11434", // Default value
  requestOptions: {
    useMMap: true,
    numThread: 6,
    numGpu: 1,
  },
});

const documents = ["Hello!", "abc"];
const embeddings = await embeddings.embedDocuments(documents);
console.log(embeddings);

对本地的文本文件进行embeddings 操作

1.文档加载

import { TextLoader } from "langchain/document_loaders/fs/text";
async function load(path) {
  const loader = new TextLoader(path);
  const docs = await loader.load();
  return docs;
}

2.对文本进行分片

import { CharacterTextSplitter } from "langchain/text_splitter";async function split(documents) {
  const splitter = new CharacterTextSplitter({
    chunkSize: 500,
    chunkOverlap: 20,
  });
  return splitter.splitDocuments(documents);
}

3.对文本块进行embeddings 

import { OllamaEmbeddings } from "@langchain/ollama";
const embeddings = new OllamaEmbeddings({
  model: "nomic-embed-text:latest",
  baseUrl: "http://192.168.0.220:11434", // Default value
  requestOptions: {
    useMMap: true,
    numThread: 6,
    numGpu: 1,
  },
});

const docs = await load("说明.txt")
const splittedDocs = await split(docs);
for (let doc of splittedDocs) {
  const embedding = await embeddings.embedDocuments(doc.pageContent)
  console.dir(embedding);
}