ollama本地部署LightRAG(已跑通)

ollama本地部署LightRAG(已跑通)
之前有用ollama本地部署过graphrag,这次尝试部署一下香港大学的LightRAG,更轻量更便捷!

一、环境配置

首先需要将LightRAG的项目拉到本地,具体可以参考github的项目,

git clone https://github.com/HKUDS/LightRAG.git

安装LightRAG所需要的依赖:

cd LightRAG
pip install -e .

安装ollama,ollama官网提供的方法速度比较慢,经常容易出现中断的现象。这里推荐修改安装脚本的方法进行安装,首先下载安装脚本并修改权限:

# 下载安装脚本
curl -fsSL https://ollama.com/install.sh -o ollama_install.sh
# 给脚本添加执行权限
chmod +x ollama_install.sh

修改下载源,打开ollama_install.sh,找到以下两个下载地址:

https://ollama.com/download/ollama-linux-${ARCH}${VER_PARAM}
https://ollama.com/download/ollama-linux-amd64-rocm.tgz${VER_PARAM}

分别修改成以下的地址,这里推荐用ctrl+H直接进行替换:

https://github.moeyy.xyz/https://github.com/ollama/ollama/releases/download/v0.3.2/ollama-linux-amd64
https://github.moeyy.xyz/https://github.com/ollama/ollama/releases/download/v0.3.2/ollama-linux-amd64-rocm.tgz

运行安装的脚本:

./ollama_install.sh 

二、模型挂起

首先将ollama服务开启

ollama serve

用到的两个模型一个是用来embedding的nomic-embed-text,一个是qwen2,分别用ollama pull到本地:

ollama pull nomic-embed-text
ollama pull qwen2
www.zeeklog.com  - ollama本地部署LightRAG(已跑通)
www.zeeklog.com  - ollama本地部署LightRAG(已跑通)

将模型挂起:

ollama run qwen2
www.zeeklog.com  - ollama本地部署LightRAG(已跑通)

挂起后可以通过一下命令查看是否挂起正常:

ollama ps
www.zeeklog.com  - ollama本地部署LightRAG(已跑通)

三、获取测试文件

按照github上面的官方教程,下载演示文本“查尔斯·狄更斯的圣诞颂歌”:

curl https://raw.githubusercontent.com/gusye1234/nano-graphrag/main/tests/mock_data.txt > ./book.txt

四、测试

首先修改./examples/lightrag_ollama_demo.py,将llm_model_name修改成qwen2,其他不变:

import os
import logging
from lightrag import LightRAG, QueryParam
from lightrag.llm import ollama_model_complete, ollama_embedding
from lightrag.utils import EmbeddingFunc

WORKING_DIR = "./dickens"

logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)

if not os.path.exists(WORKING_DIR):
    os.mkdir(WORKING_DIR)

rag = LightRAG(
    working_dir=WORKING_DIR,
    llm_model_func=ollama_model_complete,
    llm_model_name="qwen2",
    llm_model_max_async=4,
    llm_model_max_token_size=32768,
    llm_model_kwargs={"host": "http://localhost:11434", "options": {"num_ctx": 32768}},
    embedding_func=EmbeddingFunc(
        embedding_dim=768,
        max_token_size=8192,
        func=lambda texts: ollama_embedding(
            texts, embed_model="nomic-embed-text", host="http://localhost:11434"
        ),
    ),
)

with open("./book.txt", "r", encoding="utf-8") as f:
    rag.insert(f.read())

# Perform naive search
print(
    rag.query("What are the top themes in this story?", param=QueryParam(mode="naive"))
)

# Perform local search
print(
    rag.query("What are the top themes in this story?", param=QueryParam(mode="local"))
)

# Perform global search
print(
    rag.query("What are the top themes in this story?", param=QueryParam(mode="global"))
)

# Perform hybrid search
print(
    rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid"))
)

通过终端输入:

python examples/lightrag_ollama_demo.py

输出:


1. **Transformation**: A central theme is transformation, particularly exemplified by Ebenezer Scrooge's dramatic shift from a selfish, miserly businessman to a kinder and more empathetic individual over the course of one Christmas Eve. This theme is evident in his evolving interactions with ghosts from his past, present, and future experiences.

2. **Forgiveness**: Another significant theme concerns forgiveness, most notably illustrated through Scrooge's realization and regret for past wrongdoings, especially towards Tiny Tim. The narrative suggests that redemption and change are possible when one acknowledges their mistakes and seeks to amend them.

3. **Human Connection**: Emphasized by encounters with characters like Fezziwig, Bob Cratchit, Master Peter Cratchit, and the various Christmas people who embody joyous holiday traditions, this theme highlights the importance of human interaction, generosity, and shared experiences during festive times.

4. **The Importance of Giving and Kindness**: This theme is exemplified by Scrooge's initial reluctance to partake in Merry Christmas celebrations and charitable activities towards others. However, his interactions with ghosts prompt him to understand the significance of giving and kindness, leading to a transformative change within himself.

5. **The Ghostly Realm**: The spectral encounters with ghosts like Marley, the Spirit of Christmas Past, Present, and Future explore supernatural elements that guide Scrooge's personal development and societal impact. This theme underscores the power of past experiences, present realities, and future possibilities in shaping one’s behavior and understanding.

6. **The Role of Leadership**: Characters such as Alex and Taylor showcase leadership qualities crucial for guiding teams towards significant discoveries or decisions, like making First Contact with an unknown intelligence or managing a crisis response to extraterrestrial communication.

7. **Conflict and Ideological Clash**: The dynamic between Cruz and Jordan represents ideological conflicts regarding control versus freedom, order versus chaos, highlighting the tension that can exist within human societies when contrasting beliefs are present.

8. **The Legacy of Business Partnerships**: Notable through Marley's ghost, this theme explores the impact of business relationships on personal and professional outcomes after death, and how one’s actions in life affect those they leave behind.

9. **Revelation and Disclosure**: The revelation of information about the animal and Old Joe's optimistic outlook on life are examples of how new knowledge can alter perspectives and deepen character development within the story.

10. **Reflection and Learning**: This theme revolves around Scrooge’s journey of self-reflection, which ultimately leads to significant changes in his attitude and actions. His encounters with various characters allow for growth through empathy and understanding different life experiences.

By weaving these themes together, the narrative not only entertains but also offers profound insights into human nature, societal dynamics, and the transformative power of redemption and connection during festive times.
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:lightrag:Global query uses 64 entites, 60 relations, 3 text units
INFO:httpx:HTTP Request: POST http://localhost:11434/api/chat "HTTP/1.1 200 OK"
The primary themes of this text revolve around transformation, redemption, generosity, and compassion, all set against a backdrop of Christmas celebrations.

1. **Transformation**: This theme is embodied by Ebenezer Scrooge's journey from being a miserly businessman to a kindhearted soul after encountering the Ghosts of Christmas Past, Present, and Future. His experiences with these spirits force him to reconsider his past actions and contemplate the impact of kindness on personal fulfillment.

2. **Redemption**: A central theme is redemption through Scrooge's realization that he can change for the better. Through interactions with various characters like Tiny Tim and Fred, Scrooge learns about human suffering and the importance of generosity and charity, leading him to make amends for his past behavior.

3. **Generosity and Kindness**: This theme highlights the societal impact of caring for others during festive times. The Ghosts encourage Scrooge to witness various acts of generosity through their visits, which eventually inspire a change in his heart and actions towards sharing joy with those around him.

4. **Compassion**: Compassion emerges as Scrooge develops empathy for Tiny Tim's health struggles and the hardships faced by others like Bob Cratchit and the miners. This theme emphasizes that compassion is not only an emotional response but also a driving force in personal transformation and societal improvement.

5. **Community and Social Responsibility**: The story underscores the importance of community involvement, especially during Christmas time. Characters like Fred and Scrooge's sister discuss charitable actions for poor people, highlighting the role of community support and the responsibility to help those less fortunate.

6. **Legacy and Inheritance**: This theme is explored through Bob Cratchit's hopes for his son Tiny Tim and the legacy left by Jacob Marley (Scrooge's business partner). It touches on the values that families pass down, such as kindness and the importance of charitable contributions to society.

7. **Nature vs. Urbanization**: The presence of animals in London juxtaposes the urban environment with nature, symbolizing a connection between the natural world and human activities. This theme invites readers to consider how urban lifestyles impact our interactions with wildlife and natural resources.

8. **Spiritual Awakening**: Scrooge's encounters with spiritual entities like ghosts play a crucial role in his awakening from selfishness to compassion. The story suggests that supernatural experiences can lead individuals towards moral growth and transformation.

9. **Timelessness of Christmas Spirit**: Regardless of the economic challenges faced by characters like Bob Cratchit, the spirit of Christmas remains a symbol of joy and generosity that transcends financial constraints. This theme emphasizes the universal nature of festive celebrations as sources of comfort and unity.

10. **Moral Responsibility to the Underprivileged**: The text raises questions about societal responsibility towards the poor through discussions on prisons versus charity workhouses and Scrooge's reflection on the impact of his actions on those less fortunate. It encourages readers to consider ethical conduct and social justice.

These themes collectively create a rich tapestry that explores human relationships, personal growth, and societal responsibilities through the lens of Christmas traditions and supernatural experiences.
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:lightrag:Local query uses 60 entites, 55 relations, 3 text units
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:lightrag:Global query uses 64 entites, 60 relations, 3 text units
INFO:httpx:HTTP Request: POST http://localhost:11434/api/chat "HTTP/1.1 200 OK"
The top themes of "A Christmas Carol" include:

1. **Redemption** - The most prominent theme revolves around Ebenezer Scrooge's transformation from a selfish, greedy businessman to a kinder and more compassionate individual after experiencing encounters with various spirits during the night before Christmas.

2. **Happiness vs. Misery** - This theme is exemplified through contrasting the miserable life of Tiny Tim with that of Scrooge's regretful past and future projections if he does not change his ways. It also highlights the happiness found in community, generosity, and celebrating together during festive times like Christmas.

3. **Generosity and Kindness** - Throughout the narrative, characters such as Bob Cratchit, Fezziwig, and Mrs. Cratchit are shown to embody generosity and kindness, highlighting their importance in Scrooge's redemption journey.

4. **Christmas Spirit** - The story emphasizes the true meaning of Christmas through sharing, love, joy, and forgiveness. It contrasts Scrooge's initial lack of festive spirit with his eventual embracing of its essence after the encounters with the spirits.

5. **Mortality and Legacy** - Themes around death and legacy are explored as Scrooge reflects on Tiny Tim's condition and his own life choices. The Ghost of Christmas Past, Present, and Yet to Come all highlight this concept, encouraging reflection and change before it's too late.

6. **Influence of Others** - The story shows how actions have consequences and influence others both positively and negatively. Scrooge realizes the impact he has had on people like Bob Cratchit and Tiny Tim and learns about empathy through his interactions with them.

7. **Forgiveness and Redemption** - Scrooge's transformation involves forgiveness for himself and potentially for others, especially those who have wronged him in the past. His journey towards redemption is a central part of this theme.

8. **Conflict between Materialism and Human Connection** - The story contrasts Scrooge's materialistic mindset with the warmth, love, and connection that come from human interaction during festive times like Christmas.

9. **The Importance of Giving** - Characters such as the gentleman who advocates for helping poor people during Christmas and the ghost who sprinkles incense show the importance of generosity and charity towards others.

10. **Reflection on Life Choices** - The spirits guide Scrooge through his past, present, and future, encouraging him to reflect on how he has lived his life and consider what path he should take going forward.

These themes collectively intertwine throughout "A Christmas Carol," offering insights into human nature, societal values, and the transformative power of empathy and forgiveness.

至此,通过ollama本地部署LightRAG完成。

Read more

基于FPGA的北斗导航自适应抗干扰算法的设计与实现(任务书+开题报告+文献综述+代码+仿真+实物+毕业论文)

基于FPGA的北斗导航自适应抗干扰算法的设计与实现(任务书+开题报告+文献综述+代码+仿真+实物+毕业论文)

摘   要 如今,随着卫星导航技术的飞速发展,位置信息服务已经融入到我们的日常生活中,导航目前被称为继移动互联网后第三大产业。卫星导航在维护国家的安全中也发挥着不可替代的作用。为了使导航系统不受干扰的影响,本文以北斗导航系统为平台,研究基于阵列天线的自适应抗干扰算法。 首先,文章就自适应抗干扰算法的原理和方法进行了系统介绍,并在MATLAB中建立阵列模型,对基于功率倒置算法的空域抗干扰算法和空时联合抗干扰算法进行性能仿真。然后根据系统的指标,确定了在FPGA中实现抗干扰算法的方案,包括数字下变频、权值计算、数据加权、数字上变频等模块。根据权值计算模块实现方式的不同,本文提供了两种抗干扰算法在FPGA中实现的方案:一种是基于FPGA嵌入式软核NIOS II的抗干扰实现,将权值计算的过程放在NIOS II软核中,用C语言进行实现;另一种是基于逻辑语言的抗干扰算法的实现,即用硬件描述语言Verilog HDL进行权值的计算。权值计算涉及到浮点数运算和Hermite矩阵求逆,本文给出了各模块的设计方法和仿真结果,并与MATLAB仿真结果进行对比。最后给出了两种实现方案的实测结果,表明两种实

FPGA 工程师到底有哪些方向?每个岗位都在干什么?一篇给你讲清楚

FPGA 工程师到底有哪些方向?每个岗位都在干什么?一篇给你讲清楚

很多人说“学 FPGA 就是写 Verilog”,但真正进了行业才发现—— FPGA 工程师并不是一个岗位,而是一整个岗位族群。 不同公司、不同项目,对 FPGA 工程师的要求差异非常大。 如果方向选错,可能学了半年发现岗位根本不对口。 这篇文章就系统地给你拆一拆: 👉 FPGA 工程师到底有哪些岗位? 👉 每个岗位具体干什么? 👉 需要掌握哪些能力? 👉 适合什么样的人? 一、FPGA 工程师整体岗位划分(先给结论) 从企业招聘角度来看,FPGA 岗位大致可以分为 6 类: 岗位方向关键词偏向FPGA 逻辑设计工程师Verilog / 时序 / 接口核心开发FPGA 算法 / 加速工程师图像 / AI / DSP算法落地FPGA 底层驱动工程师DDR / PCIe / SerDes硬件接口FPGA 系统应用工程师Linux + FPGA系统集成FPGA 验证 / 测试仿真 / 验证质量保障FPGA 技术支持 / FA客户 / 项目支持应用型

OpenClaw-多飞书机器人与多Agent团队实战复盘

OpenClaw-多飞书机器人与多Agent团队实战复盘

OpenClaw 多飞书机器人与多 Agent 团队实战复盘 这篇文章完整记录一次从单机安装到多机器人协作落地的真实过程: 包括 Windows 安装报错、Gateway 连通、模型切换、Feishu 配对、多 Agent 路由、身份错位修复,以及最终形成“产品-开发-测试-评审-文档-运维”团队。 一、目标与结果 这次实践的目标很明确: 1. 在 Windows 上稳定跑通 OpenClaw 2. 接入飞书机器人 3. 做到一个机器人对应一个 Agent 角色 4. 支持多模型并行(OpenAI + Ollama) 5. 最终形成可执行的多 Agent 团队 最终落地状态(已验证): * 渠道:Feishu 多账号在线 * 路由:按 accountId

宇树 G1 机器人开发入门:有线 & 无线连接完整指南

宇树 G1 机器人开发入门:有线 & 无线连接完整指南

适用读者:机器人二次开发者、科研人员 开发环境:Ubuntu 20.04(推荐) 机器人型号:Unitree G1 EDU+ 前言 宇树 G1 是一款面向科研与商业应用的高性能人形机器人,支持丰富的二次开发接口。在正式进行算法调试与功能开发之前,首要任务是建立稳定的开发连接。本文将详细介绍两种主流连接方式:有线(网线直连) 与 无线(WiFi + SSH),并附上完整的配置流程,帮助开发者快速上手。 一、有线连接(推荐新手优先使用) 有线连接通过网线直接将开发电脑与 G1 机器人相连,具有延迟低、稳定性高、不依赖外部网络的优势,是新手入门和底层调试的首选方式。 1.1 前置条件 所需物品说明开发电脑推荐安装 Ubuntu 20.04,或在 Windows 上使用虚拟机宇树 G1 机器人确保已开机且处于正常状态网线(