使用 Ollama 和 Go 开发 RAG 应用程序

如何使用 Langchain、Ollama 和 Streamlit 构建 RAG 在本博客完成中,我们将指导您创建可在本地运行的 RAG 的过程。这个过程不仅会加深您对尖端语言如何计算机工作的理解,还将使您能够在自己的项目中实施它们无论您是希望将 RAG 集成到现有应用程序中,还是只是探索 NLP 的前沿领域,本教程都是您的入门之选。 阅读详情

使用 Ollama 通过 Go 创建 RAG 应用程序来利用本地模型。

关于各种开放模型,有很多话要说。其中一些被称为 Mixtral 系列,各种规模都有,而一种可能不太为人所知的是 openbiollm,这是 Llama 3 针对医疗领域的改编版。通过实现它们的 API 来测试所有这些模型需要大量工作。但是,Ollama 允许我们使用友好的界面和简单的命令行来测试它们。

在本文中,我们将在 Golang 中构建一个 RAG 应用程序,使用 Ollama 作为 LLM 服务器,使用 Elasticsearch 作为向量数据库。

步骤

  • 安装 Ollama
  • 提取数据
  • Go 中的 RAG 应用程序

安装 Ollama

什么是 Ollama?

Ollama 是一个框架,允许你使用 CLI 在本地下载和访问模型。使用简单的命令,我们可以下载、聊天和设置一个服务器,其中包含我们想要从我们的应用程序中使用的模型。

在此处下载 Ollama 安装程序:

ollama.com/

包含可用模型的库在此处:

ollama.com/library

安装 Ollama 后,我们可以通过运行其中一个可用模型来测试一切是否正常。让我们使用 3B 参数安装 llama3.2。该库包含下载和运行模型所需的命令:

在这里插入图片描述

我们将运行 3B 版本的命令:

`ollama run llama3.2:latest`代码解读

第一次,它会下载模型,然后在终端中打开聊天:

在这里插入图片描述

现在我们可以输入 /exit 退出并使用在此位置设置的服务器:http://localhost:11434。让我们测试端点以确保一切按预期运行。

Ollama 提供两种答案模式:generate 以提供单一答案,chat 以与模型进行对话:

生成 - generate

当我们只希望对单个问题得到单个答案而不需要其他答案时,我们会使用生成。

`1.  curl http://localhost:11434/api/chat -d '{
2.    "model": "llama3.2",
3.    "stream": false,
4.    "messages": [
5.      { "role": "user", "content": "Why Elastic is so cool?" }
6.    ]
7.  }'` 代码解读

默认情况下,答案以 stream: true 的形式生成,但我们将使用 stream: false,这样答案就只在一条消息中生成,并且更易于阅读。stream: true 在 UI 应用程序中很有用,因为 tokens 在生成时就会发送,而不是阻塞直到整个响应完成。

让我们继续讨论数据。

提取数据

让我们将一些医学文档作为文本和向量在 Elasticsearch 中编入索引。我们将使用这些来测试面向医学的模型(如 openbiollm)与一般模型相比的答案质量。

在开始之前,请确保我们已经创建了推理端点以使用 ELSER 作为我们的嵌入模型:

`

1.  PUT _inference/sparse_embedding/my-elser-model 
2.  {
3.    "service": "elser", 
4.    "service_settings": {
5.      "num_allocations": 1,
6.      "num_threads": 1
7.    }
8.  }

`代码解读

现在,让我们继续使用 semantic_text 字段类型创建索引,该类型允许我们控制分块大小以及向量配置。这使我们的索引能够支持全文、语义和混合搜索。

`

1.  PUT rag-ollama 
2.  {
3.    "mappings": {
4.      "properties": {
5.        "semantic_field": {
6.          "type": "semantic_text",
7.          "inference_id": "my-elser-model"
8.        },
9.        "content": {
10.          "type": "text",
11.          "copy_to": "semantic_field"
12.        }
13.      }
14.    }
15.  }

`代码解读

现在,让我们索引这些文档:

`

1.  POST _bulk
2.  {"index":{"_index":"rag-ollama"}}
3.  {"title":"JAK Inhibitors vs. Monoclonal Antibodies in Rheumatoid Arthritis Treatment","content":"This article compares the mechanisms of action, efficacy, and safety profiles of JAK inhibitors and monoclonal antibodies in rheumatoid arthritis treatment, including recent clinical trial data and real-world evidence. It discusses the intracellular signaling pathways targeted by JAK inhibitors, their rapid onset of action, and oral administration advantages. The article also covers the specific targets of various monoclonal antibodies, their long-term safety profiles, and the criteria for choosing between these two classes of drugs based on patient characteristics and disease severity."}
4.  {"index":{"_index":"rag-ollama"}}
5.  {"title":"Diagnostic Approach to Resistant Hypertension: Focus on Primary Aldosteronism","content":"This guide outlines the step-by-step diagnostic process for resistant hypertension, with a particular emphasis on screening and confirming primary aldosteronism. It details the use of aldosterone-renin ratio (ARR) testing as an initial screening tool, explaining proper patient preparation and interpretation of results. The guide also covers confirmatory tests such as the saline infusion test and captopril challenge test, their protocols, and diagnostic criteria. Additionally, it discusses the role of imaging studies in localizing aldosterone-producing adenomas and the importance of adrenal vein sampling in subtype classification of primary aldosteronism."}
6.  {"index":{"_index":"rag-ollama"}}
7.  {"title":"Gut Microbiota Diversity and Inflammatory Cytokine Production in IBD","content":"This study examines the relationship between gut microbiota diversity and the production of pro-inflammatory cytokines in inflammatory bowel diseases (IBD). It explores how reduced microbial diversity correlates with increased levels of cytokines such as TNF-α, IL-1β, and IL-6 in both Crohn's disease and ulcerative colitis. The research discusses specific bacterial species associated with anti-inflammatory effects and their mechanisms of action. Furthermore, it delves into potential therapeutic implications, including the use of prebiotics, probiotics, and fecal microbiota transplantation to modulate the gut microbiome and influence cytokine production. The study also touches on emerging microbiome-based interventions and their potential to complement existing IBD treatments."}
8.  {"index":{"_index":"rag-ollama"}}
9.  {"title":"Biological Therapy Selection in Rheumatoid Arthritis After csDMARD Failure","content":"This article provides a comprehensive framework for selecting appropriate biological therapy in rheumatoid arthritis patients who have not responded adequately to conventional synthetic Disease-Modifying Antirheumatic Drugs (csDMARDs). It discusses the various classes of biologics available, including TNF inhibitors, IL-6 inhibitors, B-cell depleting agents, and T-cell costimulation modulators. The article outlines key factors to consider in the decision-making process, such as disease activity scores, extra-articular manifestations, comorbidities, and patient preferences. It also addresses the importance of biomarkers and predictors of treatment response in guiding therapy selection. The piece concludes with a discussion on cycling versus switching mechanisms of action when faced with inadequate response to an initial biologic agent."}
10.  {"index":{"_index":"rag-ollama"}}
11.  {"title":"Hypertension Management in Chronic Kidney Disease: Special Considerations","content":"This review discusses the unique challenges in managing hypertension in patients with chronic kidney disease (CKD). It outlines the current recommendations for blood pressure targets in CKD patients, explaining how these differ based on the presence and degree of albuminuria. The article explores the preferred classes of antihypertensive medications in CKD, with a focus on renin-angiotensin system blockers and their renoprotective effects. It addresses the complexities of managing volume status in CKD and the role of diuretics. The review also covers the impact of proteinuria on treatment decisions and the need for more aggressive blood pressure control in heavily proteinuric patients. Finally, it discusses considerations for patients on dialysis and the phenomenon of reverse epidemiology in end-stage renal disease."}

`代码解读

完成了!现在我们已经准备好了模型和数据,我们可以将所有内容与我们的 Go 应用程序整合在一起。

Go 中的 RAG 应用程序

对于我们的 Go 应用程序,我们可以直接调用 Ollama 服务器,但我决定改用 parakeet。Parakeet 是一个基于 Go 文本创建 GenAI 应用程序的库。它提供了 Go 接口来抽象 HTTP 通信,此外还提供了用于嵌入、分块和内存等的帮助程序,因此创建应用程序变得非常容易。

我们将首先创建工作文件夹并设置依赖项:

`

1.  mkdir ollama-rag
2.  cd ollama-rag
3.  go mod init ollama-rag
4.  go get github.com/parakeet-nest/parakeet
5.  go get github.com/elastic/go-elasticsearch/v8@latest

`代码解读

现在,创建一个 main.go 文件,其中包含测试一切是否配置正确的最少内容:

main.go

`

1.  package main

3.  import (
4.  	"github.com/parakeet-nest/parakeet/completion"
5.  	"github.com/parakeet-nest/parakeet/enums/option"
6.  	"github.com/parakeet-nest/parakeet/llm"

8.  	"fmt"
9.  )

11.  func main() {
12.  	ollamaUrl := "http://localhost:11434"
13.  	model := "llama3.2:latest"

15.  	options := llm.SetOptions(map[string]interface{}{
16.  		option.Temperature: 0.5,
17.  	})

19.  	question := llm.GenQuery{
20.  		Model:   model,
21.  		Prompt:  "Why Elastic is so cool?, answer in one sentence",
22.  		Options: options,
23.  	}

25.  	// We use generate because we are going to run this script to ask a single question
26.  	answer, err := completion.Generate(ollamaUrl, question)
27.  	if err != nil {
28.          log.Fatal("😡:", err)
29.      }
30.  	fmt.Println(answer.Response)
31.  }

`代码解读

运行它:

`go run main.go` 代码解读

在终端中,你应该看到类似这样的答案:

`Elastic, a company known for its innovative and user-friendly software solutions, has disrupted the traditional IT industry by empowering businesses to create, deploy, and manage applications quickly and reliably.`代码解读

这个答案是基于 LLM 的训练数据,这不是我们可以提供或控制的,并且存在一些缺点:

  • 信息可能是错误的
  • 信息可能已过时
  • 无法获取来源的引用

现在,让我们创建一个名为 elasticsearch/elasticsearch.go 的文件,使用 Go 的官方客户端连接 Elasticsearch,并能够使用我们文档中的信息根据我们的数据生成有根据的答案。

注:更多有关如何连接到 Elasticsearch,摄取数据,并进行搜索,请参阅文章 “Elasticsearch:运用 Go 语言实现 Elasticsearch 搜索 - 8.x”。

elasticsearch/elasticsearch.go

``

1.  package elasticsearch

3.  import (
4.  	"context"
5.  	"encoding/json"
6.  	"fmt"
7.  	"strings"

9.  	"github.com/elastic/go-elasticsearch/v8"
10.  	"github.com/elastic/go-elasticsearch/v8/typedapi/types"
11.  )

13.  // Initializing elasticsearch client

15.  func EsClient() (*elasticsearch.TypedClient, error) {
16.  	var cloudID = "" // your Elastic Cloud ID Here
17.  	var apiKey = "" // your Elastic ApiKey Here

19.  	es, err := elasticsearch.NewTypedClient(elasticsearch.Config{
20.  		CloudID: cloudID,
21.  		APIKey:  apiKey,
22.  	})

24.  	if err != nil {
25.  		return nil, fmt.Errorf("unable to connect: %w", err)
26.  	}
27.  	return es, nil
28.  }

30.  // Searching for documents and building the context
31.  func SemanticRetriever(client *elasticsearch.TypedClient, query string, size int) (string, error) {
32.  	// Perform the semantic search
33.  	res, err := client.Search().
34.  		Index("rag-ollama").
35.  		Query(&types.Query{
36.  			Semantic: &types.SemanticQuery{
37.  				Field: "semantic_field",
38.  				Query: query,
39.  			},
40.  		}).
41.  		Size(size).
42.  		Do(context.Background())

44.  	if err != nil {
45.  		return "", fmt.Errorf("semantic search failed: %w", err)
46.  	}

48.  	// Prepare to format the results
49.  	var output strings.Builder
50.  	output.WriteString("Documents found\n\n")

52.  	// Iterate through the search hits
53.  	for i, hit := range res.Hits.Hits {
54.  		// Define a struct to unmarshal each document
55.  		var doc struct {
56.  			Title   string `json:"title"`
57.  			Content string `json:"content"`
58.  		}

60.  		// Unmarshal the document source into our struct
61.  		if err := json.Unmarshal(hit.Source_, &doc); err != nil {
62.  			return "", fmt.Errorf("failed to unmarshal document %d: %w", i, err)
63.  		}

65.  		// Append the formatted document to our output
66.  		output.WriteString(fmt.Sprintf("Title\n%s\n\nContent\n%s\n", doc.Title, doc.Content))

68.  		// Add a separator between documents, except for the last one
69.  		if i < len(res.Hits.Hits)-1 {
70.  			output.WriteString("\n-----\n\n")
71.  		}
72.  	}

74.  	// Return the formatted output as a string
75.  	return output.String(), nil
76.  }

``代码解读

EsClient 函数使用提供的云凭据初始化 Elasticsearch 客户端,SemanticRetriever 执行语义查询以构建 LLM 回答问题所需的上下文。

要查找你的云 ID 和 API 密钥,请转到此链接。

让我们回到我们的 main.go 文件并使用上述功能进行更新以调用 Elasticsearch 并运行语义查询:这将构建 LLM 上下文:

main.go

``

1.  package main

3.  import (
4.  	"fmt"
5.  	"log"
6.  	"ollama-rag/elasticsearch"

8.  	"github.com/parakeet-nest/parakeet/completion"
9.  	"github.com/parakeet-nest/parakeet/enums/option"
10.  	"github.com/parakeet-nest/parakeet/llm"
11.  )

13.  func main() {

15.  	ollamaUrl := "http://localhost:11434"
16.  	chatModel := "llama3.2:latest"
17.  	question := `Summarize document: JAK Inhibitors vs. Monoclonal Antibodies in Rheumatoid Arthritis Treatment`
18.  	size := 3

20.  	esClient, err := elasticsearch.EsClient()

22.  	if err != nil {
23.  		log.Fatalln("😡:", err)
24.  	}

26.  	// Retrieve documents from semantic query to build context
27.  	documentsContent, nil := elasticsearch.SemanticRetriever(esClient, question, size)

29.  	systemContent := `You are a helpful medical assistant. Only answer the questions based on found documents.
30.  	Add references to the base document titles and be succint in your answers.`

32.  	options := llm.SetOptions(map[string]interface{}{
33.  		option.Temperature: 0.0,
34.  	})

36.  	queryChat := llm.Query{
37.  		Model: chatModel,
38.  		Messages: []llm.Message{
39.  			{Role: "system", Content: systemContent},
40.  			{Role: "system", Content: documentsContent},
41.  			{Role: "user", Content: question},
42.  		},
43.  		Options: options,
44.  	}

46.  	fmt.Println()
47.  	fmt.Println("🤖 answer:")

49.  	// Answer the question
50.  	_, err = completion.ChatStream(ollamaUrl, queryChat,
51.  		func(answer llm.Answer) error {
52.  			fmt.Print(answer.Message.Content)
53.  			return nil
54.  		})
55.  	if err != nil {
56.  		log.Fatal("😡:", err)
57.  	}

59.  	fmt.Println()
60.  }

``代码解读

如你所见,我们将用户的问题连同与之相关的所有文档一起发送。这就是我们如何根据 Elasticsearch 中的文档获得答案。

我们可以通过运行代码进行测试:

`go run .`代码解读

你应该看到类似这样的内容:

According to the article “JAK Inhibitors vs. Monoclonal Antibodies in Rheumatoid Arthritis Treatment”, JAK inhibitors and monoclonal antibodies are two classes of drugs used to treat rheumatoid arthritis (RA). The main difference between them lies in their mechanisms of action:

    JAK inhibitors target intracellular signaling pathways, specifically the Janus kinase (JAK) pathway, which is involved in inflammation and immune response. They have a rapid onset of action and are administered orally.
  • Monoclonal antibodies target specific proteins involved in the inflammatory process, such as tumor necrosis factor-alpha (TNF-α), interleukin-6 (IL-6), and interleukin-17 (IL-17).

The article highlights that JAK inhibitors have a more favorable safety profile compared to monoclonal antibodies, with fewer gastrointestinal side effects. However, the choice between these two classes of drugs depends on patient characteristics and disease severity.

“References:”

    "JAK Inhibitors vs. Monoclonal Antibodies in Rheumatoid Arthritis Treatment" (document title)

Parakeet 将为我们处理 Ollama 交互,包括 token 流!从现在开始,我们可以非常轻松地测试不同的模型,而无需更改代码。

除了主库中的模型外,我们还可以访问社区成员上传的模型。

要使用其中一个,我们只需确保先下载到 Ollama 中。例如,让我们测试 openbiollm:

`ollama run taozhiyuai/openbiollm-llama-3:8b_q8_0`代码解读

安装后,我们可以将它与我们的 Go 代码一起使用:

`chatModel := "taozhiyuai/openbiollm-llama-3:8b_q8_0"`代码解读

让我们用同样的问题再运行一次。你注意到有什么不同吗?

In rheumatoid arthritis treatment, JAK inhibitors and monoclonal antibodies are commonly used. This article discusses the benefits and drawbacks of both therapies. JAK inhibitors work by targeting intracellular signaling pathways involved in the immune response. They have a rapid onset of action and can be administered orally, making them convenient for patients. Recent clinical trial data has shown that JAK inhibitors are effective at reducing inflammation and slowing joint damage progression in rheumatoid arthritis. However, there is still ongoing research to fully understand their long-term safety profile. Monoclonal antibodies, on the other hand, specifically target molecules involved in the immune system. These drugs have been found to be highly effective in managing symptoms of rheumatoid arthritis and improving joint function. They can provide prolonged symptom control and are often used as first-line treatment options. However, due to their complexity and unique administration requirements, monoclonal antibodies may not be suitable for all patients. In conclusion, both J AK inhibitors and monoclonal antibodies have their own advantages and disadvantages in treating rheumatoid arthritis. The choice of therapy depends on individual patient characteristics and disease severity. Ongoing research will contribute to a deeper understanding of the efficacy and safety profiles of these treatments, ultimately leading to improved care for patients with rheumatoid arthritis.

openbiollm 模型似乎提供了更多有关技术术语的细节,但它没有遵循有关引用上下文中提供的文档和给出简短答案的说明。相比之下,Llama3.2 更好地遵循了说明。

你可以在此处找到完整的工作示例

结论

Ollama 提供了一种非常直接和简单的方法来下载和测试不同的开放模型,从知名的模型到社区成员微调的模型。将它与 Parakeet 和官方 Elasticsearch Go 客户端配对,可以非常轻松地创建 RAG 应用程序。此外,通过使用 semantic_text 字段类型,你可以创建一个使用 ELSER(Elastic Sparse 嵌入模型)的语义查询就绪索引,而无需任何其他配置,从而简化了分块、索引和向量查询过程。

Elasticsearch 与行业领先的 Gen AI 工具和提供商进行了原生集成。查看我们的网络研讨会,了解如何超越 RAG 基础知识,或构建可用于生产的应用程序 Elastic Vector Database。

要为你的用例构建最佳搜索解决方案,请立即开始免费云试用或在你的本地机器上试用 Elastic。

​

如何学习AI大模型?

作为一名热心肠的互联网老兵,我决定把宝贵的AI知识分享给大家。 至于能学习到多少就看你的学习毅力和能力了 。我已将重要的AI大模型资料包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来。

这份完整版的大模型 AI 学习资料已经上传优快云,朋友们如果需要可以微信扫描下方优快云官方认证二维码免费领取【保证100%免费】

一、全套AGI大模型学习路线

AI大模型时代的学习之旅:从基础到前沿,掌握人工智能的核心技能!

img

二、640套AI大模型报告合集

这套包含640份报告的合集,涵盖了AI大模型的理论研究、技术实现、行业应用等多个方面。无论您是科研人员、工程师,还是对AI大模型感兴趣的爱好者,这套报告合集都将为您提供宝贵的信息和启示。

img

三、AI大模型经典PDF籍

随着人工智能技术的飞速发展,AI大模型已经成为了当今科技领域的一大热点。这些大型预训练模型,如GPT-3、BERT、XLNet等,以其强大的语言理解和生成能力,正在改变我们对人工智能的认识。 那以下这些PDF籍就是非常不错的学习资源。 img

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

四、100+套大模型面试题库

在这里插入图片描述

五、AI大模型商业化落地方案

img

作为普通人,入局大模型时代需要持续学习和实践,不断提高自己的技能和认知水平,同时也需要有责任感和伦理意识,为人工智能的健康发展贡献力量。

Agentic RAG:智能体驱动的动态检索系统Golang实战 传统检索增强生成(RAG)系统在简单问答场景中表现出色,但在处理复杂、多步骤查询时存在显著局限。本文介绍——一种智能体驱动的动态检索系统,通过查询重写、动态路由、工具调用和自我反思等能力,将传统RAG升级为具备自主决策能力的智能工作流。我们将使用Golang实现完整的Agentic RAG系统,代码占比超过60%,包含可运行的企业级示例。智能查询理解:通过LLM驱动的查询重写,深入理解用户真实意图动态路由决策:根据查询类型智能选择最佳检索源,提升召回率工具调用扩展。 阅读详情

相关推荐

Go 语言实现 RAG 系统:从原理、架构到生产级工程落地

向量召回的 Top20 并不等于“最适合拿去生成的 Top5”。向量相近不代表答案性强。候选结果可能重复。候选片段可能缺少关键细节。query + 候选片段输出:更可信的排序分数提升答案命中率减少上下文噪声降低 LLM token 成本ID stringID stringGo 语言非常适合承担 RAG 系统中的“工程底座”角色。高并发在线服务异步文档处理流水线检索与重排编排限流、缓存、观测、治理微服务与容器化部署切块是否合理元数据是否完整召回是否稳定。

一起修行,不孤单。这里有编程语言、开发工具、学习方法论和踩坑笔记。用简单的话说复杂的事,陪你从小白到进阶。周更干货,欢迎一起成长! 393

【LLM大模型】使用Ollama本地离线体验SimpleRAG(手把手教程)

Ollama是一个开源项目,专注于开发和部署大语言模型,特别是像LLaMA这样的模型,用于生成高质量的文本和进行复杂的自然语言处理任务。

2301_81940605的博客 2067

用 Go + Ollama 构建本地离线 RAG 知识库系统

但云端 API 调用存在成本、隐私、稳定性等问题。**原因**:OpenAI 兼容接口配置了 `/v1` 前缀,但 Ollama 原生 API 是 `/api/embed`- ✅ **本地模型适配** - 支持 Ollama、OpenAI、DeepSeek 多后端。1. **流式输出** - 添加 SSE 接口 `/api/v1/chat/stream`**错误**:配置值包含注释内容,如 `ollama" # 可选...`**总结**:通过本项目,实现了完全离线的 RAG 知识库系统。

weixin_43243949的博客 327

通过 Ollama、Langchain 实现 RAG

RAG 在 Langchain 上的定义是,作为大语言模型最常用的场景就是问答系统,可以针对特别来源数据做问题回答,就是私有数据,这就是 RAG,英文全称是Retrieval Augmented Generation。就是对现有模型数据的增广,大语言模型都是在公众数据上训练,而且只是拿到了某一个时间点之前的数据。RAG 是数据增广,也可以说是数据过滤,按照今天大模型的发展,上下文的长度已经卷到200 万个汉字的无损上下文,那么 RAG 会不会以后就不需要了,每次对话都把文档带上,让我们拭目以待。

hawk2014bj的博客 5084

Ollama 运行 Cohere 的 command-r 模型

Ollama 运行 Cohere 的 command-r 模型

engchina的专栏 2842

MFC+Modbus-Tcp协议实现温湿度传感器采集

本文简单介绍MFC使用-Tcp通信实现系列MODBUSTCP型温湿度传感器采集数据。

zhigang_zhao的博客 2831

Elasticsearch:使用 Ollama 和 Go 开发 RAG 应用程序

使用 Ollama 通过 Go 创建 RAG 应用程序来利用本地模型。关于各种开放模型,有很多话要说。其中一些被称为 Mixtral 系列,各种规模都有,而一种可能不太为人所知的是 openbiollm,这是 Llama 3 针对医疗领域的改编版。通过实现它们的 API 来测试所有这些模型需要大量工作。但是,Ollama 允许我们使用友好的界面和简单的命令行来测试它们。在本文中,我们将在 Golang 中构建一个 RAG 应用程序,使用 Ollama 作为 LLM 服务器,使用 Elastics

Elastic 中国社区官方博客 2295

运放偏置电路设计:如何精准计算差分放大器的电压偏移量

本文深入解析了差分放大器偏置电路的设计原理与精准计算方法,重点阐述了如何通过引入参考电压实现信号电压偏移,以适应单电源ADC的输入范围。文章结合实战案例,详细推导了偏移电压公式,并强调了电阻匹配、运放选型及PCB布局对精度和共模抑制比的关键影响,帮助硬件工程师避免常见设计陷阱。

weixin_29288313的博客 634

Go + Ollama 在本地构建你的 RAG 应用

这篇文章会引导大家使用 Golang 设置本地大型语言模型 (LLM) 并与之交互,以此在本地构建你的 AI 应用。首先,我们需要在本地计算机上运行 LLM。为此,我们将使用 Ollama(可在[1] 上获取)。虽然本地加载模型有多种选择,但我发现 Ollama 是相对容易使用的。Ollama 支持 macOS、Linux 和 Windows。本文的代码还没有在 Windows 上测试过,所以我这里重点介绍 macOS 和 Linux,但在 Windows 上的过程应该类似。

python1222_的博客 2553

网络安全学习路线是怎样的?

为什么要学习安全? 近几年网络安全事件层出不穷,相信大家哪怕没遇到过,但也听过不少了吧。如服务器遭受入侵被黑,用户帐号被盗;被钓鱼、勒索病毒等,这些一旦发生,对企业而言都是不小的打击。因此,网络安全不容忽视,同时随着时代的不断发展,公司对于运维及网络工程师要求也越来越严格。未来越来越吃香的一定是技能方向广的复合型人才。网络安全可以说是一条非常好的发展道路。 今年两会期间,全国政协委员,360集团创始人、董事长周鸿祎提交了关于网络安全行业特殊人才的提案,为广大白帽子人员争取更好...

网安技术分享 8697

拆开一个烧坏的IGBT模块,手把手教你识别过压、过流、过温的“案发现场”

本文详细解析了IGBT模块失效分析的实战技巧,通过观察铝层熔化纹路、焊锡溢出形态等物理痕迹,手把手教你识别过压、过流、过温的典型失效模式。文章提供了从基础工具包到现场快速诊断的完整流程,帮助工程师精准定位IGBT模块失效的根本原因。

weixin_30655569的博客 426

使用Ollama和Go基于文本嵌入模型实现文本向量化

基于RAG+大模型的应用已经成为当前AI应用领域的一个热门方向。RAG(Retrieval-Augmented Generation)将检索和生成两个步骤相结合,利用外部知识库来增强生成模型的能力(如下图来自网络)。在RAG赋能的大模型应用中,关键的一步是将文本数据向量化后存储在向量数据库中(如上图的红框),以实现快速的相似度搜索,从而检索与输入查询相关的文本片段,再将检索到的文本输入给生成模型生...

TonyBai 3314

Dify 从入门到精通:第一篇 - 基础介绍与快速上手

Dify是一个开源的低代码平台,旨在简化大型语言模型(LLM)应用的开发流程。本文作为"Dify从入门到精通"系列的首篇,全面介绍了Dify的核心概念、安装步骤和基本使用方法。文章首先解析了Dify的多模型支持、低代码开发等特点,然后详细讲解了基于Docker的安装配置过程,包括系统要求、环境变量设置等。通过创建一个邮件助手应用的实际示例,展示了Dify的可视化工作流设计功能。最后简要介绍了高级特性和最佳实践,为后续深入学习奠定基础。本文为开发者提供了从零开始使用Dify构建AI应用的完

IT深耕十余载,大道之简 1147

LLM之Ollama:ollama的简介、安装和使用方法、案例应用之详细攻略

​ LLM之ollama:ollama的简介、安装和使用方法、案例应用之详细攻略 目录 ollama的简介 ollama的安装和使用方法 ollama的案例应用 ollama的简介 ollama是一款可以开始使用本地的大型语言模型。启动并运行大型语言模型。运行Llama 2、Code Llama和其他模型。自定义并创建您自己的模型。 官网:Ollama GitHub地址:GitHub - ollama/ollama: Get up and

头部AI社区如有邀博主AI主题演讲请私信—心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,专注,谦虚,自律,反思,成长,还算比较正能量的博主,公益免费传播…内心特别想在AI界做出一些可以推进历史进程影响力的技术(兴趣使然,有点小情怀,也有点使命感呀 2万+

IIS - 会话cookie中缺少HttpOnly属性

不啰嗦,我们直接开始! 先进行常规设置 打开配置编辑器 选中图中节点,将httpOnlyCookies设置为true 然后。。。不起作用。。。 换种方式 通过配置出站规则getcookie添加HttpOnly 在Web.config中添加如下出站规则 <rewrite> <outboundRules> <rule name="Add HttpOnly"> <match serverVa.

。 21万+

空心杯电机在美容仪器中的应用:为什么你的洗脸刷动力这么强?

本文深入解析了空心杯电机如何成为高端美容仪器的核心动力源。通过对比传统电机,揭示了其无铁芯、低惯量、零齿槽效应的技术优势,从而实现了强劲动力、极致静音与细腻震动的用户体验。文章详细阐述了空心杯电机在洁面刷、导入仪等美容仪器中的具体应用与选型考量,并指出了开发中驱动匹配、测试等关键实战要点。

j2k3l4的博客 1013

构建本地运行的RAG系统:Langchain、Ollama和Streamlit实现

随着大型语言模型(LLM)能力的不断提升,越来越多基于OpenAI和Anthropic等巨头LLM提供商的应用正在涌现。这些应用背后的核心技术是检索增强生成(RAG)框架。本文将跳过RAG的基础知识,直接指导读者如何构建一个可以在本地笔记本电脑上运行的RAG应用,无需担心数据隐私和token成本问题。我们将构建一个类似ChatPDF但更简单的应用。用户可以上传PDF文档,并通过简单的用户界面提问。我们的技术栈非常简单,包括Langchain、Ollama和Streamlit。

Nifc666的博客 1028

Trustzone/TEE/安全 面试100问-目录

关键词:cache学习、mmu学习、cache资料、mmu资料、arm资料、armv8资料、armv9资料、 trustzone视频、tee视频、ATF视频、secureboot视频、安全启动视频、selinux视频,cache视频、mmu视频,armv8视频、armv9视频、FF-A视频、密码学视频、RME/CCA视频、学习资料下载、免费学习资料、免费 周贺贺,baron,代码改变世界ctw,Arm精选, 资深安全架构专家,十年手机安全/SOC底层安全开发经验。擅长trustzone/tee安全产品的设计

baron-周贺贺-代码改变世界ctw 649

Ollama 支持模型微调 也支持支持词库,支持RAG,go语言开发的大模型的推理应用,

Ollama 支持模型微调(主要是 LoRA 轻量微调),需结合外部工具训练权重 + Modelfile 加载;无直接“词库微调”功能,词库增强优先用 RAG 实现(更易维护、成本更低);只有需要“固化核心词库知识、无动态更新需求”时,才考虑 LoRA 微调。如果你的词库是固定的小体量知识(比如几十条),微调是可行的;如果词库会频繁更新,RAG 是更优解。

AI 前沿技术实战博客:LLM / Agent / AI 制药 / 生信四大栏目日更,硬核干货 + 可复现代码,看完就能上手 1012

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

VecDB第一篇:Go + Ollama 构建的tinyRAG应用, 如何将本地prompt知识库传送到deepseek。Prompt提示工程RAG。

本文介绍了一个基于Go语言和Ollama构建的轻量级RAG系统,专为非技术背景的眼科医生客户设计。系统采用提示词工程方式,将本地知识库(txt文件)与用户问题结合后通过Ollama调用DeepSeek模型生成回答,省去了复杂的数据库设置。项目结构简单,包含知识库加载、Ollama接口调用等核心功能模块,支持通过配置文件调整运行参数。安装只需下载Ollama、DeepSeek模型并编译运行Go代码即可。系统针对老年用户优化了操作方式,仅需将知识库文件放入指定目录即可使用,实现了技术门槛低、部署简单的智能客服解

636

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

基于Ollama+AnythingLLM快速搭建本地RAG系统

从chat对话中可以看出基于上传的文档,可以回答简单的问题;对于中文文档推理的效果较差。安装后搜索AnythingLLM或在桌面快捷方式打开程序,兼容多种LLM模型。执行上述命令会在本地的114343端口启动服务,可以供外部调用。基于Ollama+AnythingLLM快速搭建本地RAG系统。embedding模型: nomic-embed-text。下载windows安装包,双击下一步安装即可。操作系统:windows11 23H2。llm模型: gemma:2B。1. 下载安装Ollama。

lldhsds的专栏 5272

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

从零开始构建RAG应用:chromem-go + Ollama 本地部署终极指南 [特殊字符]

想要构建一个完全本地运行的智能问答系统吗?chromem-go 是一个轻量级的 Go 语言向量数据库,结合 Ollama 本地大语言模型,让你能够**零成本、零依赖**地搭建强大的 RAG(检索增强生成)应用。本文将为你提供完整的本地部署指南,无需任何云端 API 密钥,保护你的数据隐私。 ## 什么是 chromem-go?🤔 chromem-go 是一个**嵌入式向量数据库**,采用类似

gitblog_00165的博客 384

本地AI服务搭建:Ollama+LobeChat+Go实战

利用Ollama在本地部署大语言模型,结合Go语言调用API实现智能对话,并通过LobeChat构建可视化交互界面,兼顾数据隐私与高性能,适用于客服、教育、医疗等场景。

weixin_32242475的博客 832
上一篇: 这本大模型书太绝了!《自然语言处理新范式:基于预训练模型的方法》真的不要太强(附PDF)
下一篇: 大模型好书安利:《大模型时代:ChatGPT开启通用人工智能浪潮》(附学习PDF)
AI_小站
博客等级 码龄3年 6255粉丝 1152原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值