全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件
574 0
2025-11-12
腾讯混元大模型是腾讯公司自主研发的全链路解决方案,在高质量内容创作、数理逻辑分析、代码生成、多轮对话以及图像和视频生产等方面表现优异,处于行业领先地位。我一直希望能在我个人的电脑上安装并尝试使用。本文中,我将详细介绍安装过程,并说明如何连接到Elasticsearch。

注意:以下是基于最新的Elastic Stack 9.2.0版本进行演示,其界面可能与之前版本有所区别。

安装混元大模型

我希望使用Ollama来完成安装。遗憾的是,目前混元大模型尚不支持直接通过Ollama安装。我在国内网站上搜索了一番,发现很少有关于如何安装的详细指南。腾讯混元-4B(及其更小版本)可以与Ollama兼容,但现阶段还无法直接使用。你需要利用与llama.cpp兼容的GGUF量化版本,并将其封装为自定义Ollama模型。

Ollama采用llama.cpp引擎,该引擎支持GGUF格式的模型——包括已转换或下载为GGUF格式的Hunyuan-4B。

Hugging Face上已经提供了一个可以直接使用的量化版本:mradermacher/Hunyuan-4B-Instruct-GGUF

详细安装步骤:

步骤1:安装Ollama

请从Download Ollama on macOS下载适用于macOS、Windows或Linux的Ollama。 按照安装程序指示完成安装,完成后,在终端运行以下命令以验证:
ollama --version
$ ollama --version
ollama version is 0.12.9

步骤2:下载GGUF模型

从下列版本中选择一个(如Q4_K_M,以便在质量和速度之间取得平衡):
mkdir -p ~/.ollama/models/hunyuan-4b
cd ~/.ollama/models/hunyuan-4b
curl -L -O https://huggingface.co/mradermacher/Hunyuan-4B-Instruct-GGUF/resolve/main/Hunyuan-4B-Instruct.Q4_K_M.gguf
$ ls .ollama/models/
blobs     manifests
$ mkdir -p ~/.ollama/models/hunyuan-4b
$ ls ~/.ollama/models
blobs      hunyuan-4b manifests
$ cd ~/.ollama/models/hunyuan-4b
$ curl -L -O https://huggingface.co/mradermacher/Hunyuan-4B-Instruct-GGUF/resolve/main/Hunyuan-4B-Instruct.Q4_K_M.gguf
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1353  100  1353    0     0    966      0  0:00:01  0:00:01 --:--:--   966
100 2486M  100 2486M    0     0  5854k      0  0:07:14  0:07:14 --:--:-- 4677k

步骤3 – 创建自定义Modelfile

在~/.ollama/models/hunyuan-4b/Modelfile中创建以下内容:
FROM ./Hunyuan-4B-Instruct.Q4_K_M.gguf
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER num_ctx 4096
TEMPLATE """{{ .System }}
User: {{ .Prompt }}
Assistant:"""
SYSTEM "You are Hunyuan, a helpful Chinese assistant developed by Tencent."
$ vi ~/.ollama/models/hunyuan-4b/Modelfile

步骤4 – 在Ollama中注册模型

ollama create hunyuan-4b -f ~/.ollama/models/hunyuan-4b/Modelfile
$ ollama create hunyuan-4b -f ~/.ollama/models/hunyuan-4b/Modelfile
gathering model components ? 
gathering model components 
copying file sha256:def49bb81ddbecf7c2e3aa557716b915607c6fd3af7e73316c16464321d5da22 100% 
parsing GGUF 
using existing layer sha256:def49bb81ddbecf7c2e3aa557716b915607c6fd3af7e73316c16464321d5da22 
creating new layer sha256:8e48700b8cb5619c3a31e83a13a321070a62ee259d91e1b81b1d2b9eda4a459f 
creating new layer sha256:7127d492f5e2ee2a8d4fbfd439094e35f3c13ebc9f07f6e9c9fd64f9cc243f16 
creating new layer sha256:dedcbf3159e051675ba89642680de2bbfcac020a3f2c1afde851e27629484659 
writing manifest 
success

步骤5 – 运行模型

ollama run hunyuan-4b
$ ollama run hunyuan-4b
>>> what is Elastic?
 1. **Definition:** Elastic refers to the ability of an object or system to change shape or size in response to 
external forces without permanent deformation. In simpler terms, it means "bending" or "stretching".
2. **Types of Elasticity:**
    * **Elastic (or Young's Modulus):** The property where an object returns to its original shape after the 
force is removed.
    * **Yield:** When an object deforms permanently even without a constant force applied, it is called yield. A 
material that exhibits both elastic and yield properties is called "durable".
3. **Applications of Elasticity in Physics:**
    * **Coding (Elastic Database):** Elastic is the name given to the database system by MongoDB.
    * **Engineering:** Elasticity is used in designing structures like bridges, buildings, etc., ensuring they 
can withstand external forces without permanent deformation.
    * **Biology:** Elastic tissues such as muscle and skin are involved in various functions in living organisms.
4. **Elasticity in Software Engineering:** The term "elastic" is often used to describe systems that have the 
ability to change their structure or behavior dynamically, adapting to changes in the environment or user input 
without a need for complex code modifications.
5. **Elasticity in Physics (Reinforced Elasticity):** A phenomenon where materials undergo multiple rounds of 
deformation before returning to their original shape (e.g., rubber bands). This is useful in applications like 
car tires, where repeated pressure and release causes small changes in the tire's shape, improving fuel 
efficiency.
</think>
<answer>
Okay, let's break down what "Elastic" means.

1.  **Core Definition:** In a broad sense, "elasticity" refers to the property of an object or material that can 
change its shape or size when subjected to stress (force) and return to its original shape after the stress is 
removed.
    *   Think of stretching a rubber band: it gets longer (deforms), and if you let go, it snaps back to its 
original length. That's elastic deformation.

2.  **Types in Physics:**
    *   **Elastic Deformation:** The object returns to its original shape after the force is removed. Examples 
include a spring or a metal rod.
    *   **Yield (or Ductile Deformation):** The object deforms permanently even without constant stress, and 
sometimes it will later return to some extent. A material that can undergo both elastic and yield deformation is 
called "ductile."
    *   **Plastic Deformation:** Permanent shape changes that cannot be easily reversed by the removal of stress.

3.  **Why Elasticity Matters (Applications):**
    *   **Engineering & Architecture:** Designing buildings, bridges, and other structures allows for them to 
withstand external forces like wind, earthquakes, or traffic loads without collapsing permanently.
    *   **Biology:** Muscles and skin are elastic tissues that allow movement and flexibility in living 
organisms.
    *   **Physics & Chemistry (Elastic Bands):** Used in demonstrations of elasticity, as mentioned 
above.
    *   **Materials Science:** Understanding how different materials respond to stress helps in selecting the 
right material for specific applications.

4.  **"Elastic" in Software Development:**
    *   While not a physical property like in physics or engineering, the term "elastic" is often used 
metaphorically in software development:
        *   An **Elastic Database** (like MongoDB) is designed to scale up and down automatically when the number 
of users or data grows. It can handle increased load without requiring manual intervention from developers.
        *   An **Elastic System** can adapt its behavior or structure dynamically in response to changes, making 
it more flexible and resilient than a rigid system.

In summary, "elastic" describes something that can stretch (or compress) and return to its original state. This 
property is crucial for many physical systems and also leads to the concept of scalable and adaptable software 
architectures.
</answer>

>>> What is Elasticsearch?
 Okay, let's break down what "Elasticsearch" means.

1.  **Elastic as a Metaphor:** The name comes from the Greek adjective "ellastos," meaning "to stretch." In the 
context of computing, it refers to the ability of software systems to scale and adapt dynamically without 
requiring manual intervention or complex code changes.
2.  **Core Concept - Scalability & Elasticity:**
    *   **Scalability (Up-Scaling):** The system can handle a significantly larger number of users or data volume 
without performance degradation or crashes. For example, when more people start using a web application, the 
database can automatically add more capacity.
    *   **Elasticity (Auto-Sharding & Rebalancing):** When the load on an Elasticsearch node decreases, it can 
remove resources from that node and move them to other nodes with less load. Conversely, if a node becomes 
overloaded, it can be assigned new clients or data chunks. This automatic distribution of work keeps the system 
balanced and responsive.

3.  **Analogy:** Think of your car's engine or brakes being "elastic." If you use more gas (stress), the engine 
heats up slightly. When you let off the gas and turn it off, the heat dissipates back to normal (returns to 
original state). Similarly, Elasticsearch manages its resources dynamically based on current load.

4.  **Why Use Elasticsearch?**
    *   **High Availability & Fault Tolerance:** It's designed for distributed systems, making it resilient even 
if some nodes or data shards fail.
    *   **Real-time Search and Analytics:** It excels at quickly indexing large amounts of text (like website 
content) and retrieving relevant information in near real-time.
    *   **Distributed Nature:** Data is sharded across many machines, allowing for massive storage and retrieval 
capabilities far beyond a single machine's limits.
    *   **Suitable for Log Data & Large Datasets:** It's commonly used to store and analyze logs from 
applications, servers, or IoT devices.

5.  **Common Use Cases:**
    *   **Search Engines (like Solr):** Elasticsearch powers much of Google Search (as part of the search 
infrastructure).
    *   **Log Management & Monitoring:** Storing and analyzing application logs for performance monitoring and 
troubleshooting.
    *   **Data Indexing/Analysis:** As a backend database for applications that need to perform complex queries 
or aggregations on large datasets.
    *   **Real-time Analytics Dashboards.**

In essence, Elasticsearch is a distributed, fault-tolerant search engine designed for high scalability and 
elasticity in the context of data indexing, retrieval, and analysis. It's a fundamental technology for modern 
data-driven applications.
</answer>

>>> 中国最长的河流是哪条河?
 中国最长的河流是**长江**。

*   **长度:**约6,300公里。这是一条非常长的河流,也是亚洲第一长河。
*   **流经地区:**发源于青海省青藏高原的唐古拉山脉各拉丹冬峰西南侧(还有说法认为发源于四川的沱沱河),自西向东流经
青海、西藏、四川、云南、重庆、湖北、湖南、江西、安徽、江苏、上海11个省级行政区,最后注入东海。
*   **流域面积:**约94万平方公里。
*   **重要性:**
    *   **经济命脉:**是长江经济带的核心,对促进沿线地区的经济发展至关重要。长江沿岸拥有全国大部分的重要城市和经济
带核心区域。
    *   **农业灌溉:**提供大量灌溉用水,支撑着沿岸的农业发展。
    *   **航运价值高:**拥有黄金水道之称,通航里程长,货运量巨大,是中国乃至世界重要的内河运输通道之一(部分河段如
南京到武汉的长江航道已通江)。
    *   **生态与旅游:**拥有丰富的生物多样性和独特的自然景观,是重要的水电资源和旅游资源。
    *   **国防意义:**其地理形势对维护国家安全和领土完整具有重要意义。

因此,无论是从长度还是经济、社会等综合角度来看,长江都是中国最重要的河流之一。
</answer>
可以在另一个终端输入以下命令进行测试:
curl http://localhost:11434/api/generate -d '{
  "model": "hunyuan-4b",
  "stream": false,
  "prompt": "What is hybrid search in Elasticsearch?"
}'

连接到Elasticsearch

接下来,我们可以参考文章“Elasticsearch:在Elastic中玩转DeepSeek R1来实现RAG应用”中的步骤连接到Elasticsearch。首先按照文中所述安装自己的Elasticsearch及Kibana,并安装好E5模型。

创建Connector

我们根据以下参数进行配置: Connector name:hunyuan-4b 选择OpenAI provider:other (OpenAI Compatible Service) URL:http://localhost:11434/v1/chat/completions 请将URL调整为你的ollama正确路径。如果你从容器内部调用,请记得替换host.docker.internal或等效项。 默认模型:hunyuan-4b API 密钥:创建一个,需要输入,但实际值无关紧要 点击上面的“Save & test”按钮: 从上述测试中可以看出,测试是成功的。

上传文档并在Playground中进行测试

接下来使用与“Elasticsearch:在Elastic中玩转DeepSeek R1来实现RAG应用”文中相同的文档进行测试。 Instructions:
You are an assistant for question-answering tasks using relevant text passages from the book Alice in wonderland
很有趣,混元模型的响应速度比我预期的要快。至少比上次使用DeepSeek R1时要快很多。我们尝试用中文进行提问:
谁出现在茶会上?
文章有哪些章节?
如果你想通过代码完成查询,那么请按照以下步骤操作: 可以点击上面的复制图标,并进行相应的修改即可。具体操作步骤,请参阅我之前的文章。

Elasticsearch:在 Elastic 中灵活运用 DeepSeek R1 来构建 RAG 应用。

好了,今天的分享就到这里。祝大家学习顺利!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群