LightRAG开源了…结合本地ollama实现股票数据接口Akshare智能问答
LightRAG`是由香港大学研究团队推出的一种检索增强生成(Retrieval-Augmented Generation, RAG)系统。该系统通过整合图结构索引和双层检索机制,显著提升了大型语言模型在信息检索中的准确性和效率。`LightRAG` 不仅能够捕捉实体间的复杂依赖关系,还能全面理解信息,处理具体和抽象查询,确保用户获得既相关又丰富的响应。
核心特点
1. 图结构索引:
`LightRAG` 利用图结构索引,有效地捕捉和表示实体之间的复杂依赖关系。这种索引方式使得模型能够更好地理解信息的内在结构,提高检索的准确性。
2. 双层检索机制:
`LightRAG` 采用了双层检索机制,第一层进行初步检索,筛选出候选结果;第二层则对候选结果进行深入分析,进一步提升检索的精确度。这种机制确保了在大规模数据集中也能高效、准确地找到相关信息。
3. 全面理解信息:
- 通过图结构索引和双层检索机制,`LightRAG` 能够全面理解信息,不仅处理具体查询,还能应对抽象查询。无论用户的问题是明确的还是模糊的,`LightRAG` 都能提供既相关又丰富的响应。
4. 快速适应新数据:
- `LightRAG` 具备快速适应新数据的能力,能够在动态环境中保持高效和准确。系统基于增量更新算法,能够及时整合新数据,而无需重建整个知识库。这使得 `LightRAG` 在不断变化的信息环境中依然保持出色的性能。
技术细节
1. 图结构索引:
- 图结构索引通过节点和边来表示实体及其关系,能够捕捉实体间的复杂依赖关系。这种索引方式不仅提高了检索的准确性,还增强了模型的理解能力。
2. 双层检索机制:
- 第一层检索:利用初步检索算法,从大规模数据集中筛选出候选结果。
- 第二层检索:对候选结果进行深入分析,进一步提升检索的精确度。这种双层机制确保了在大量数据中也能高效、准确地找到相关信息。
3. 增量更新算法:
- `LightRAG` 采用增量更新算法,能够及时整合新数据,而无需重新构建整个知识库。这使得系统在动态环境中能够快速适应新信息,保持高效和准确。
应用场景
1. 搜索引擎:
- 在搜索引擎中,`LightRAG` 可以显著提升搜索结果的相关性和丰富性,提供更好的用户体验。
- 通过图结构索引和双层检索机制,`LightRAG` 能够更准确地理解用户的查询意图,返回更符合需求的搜索结果。
2. 智能客服:
- 在智能客服系统中,`LightRAG` 可以快速响应用户的咨询,提供准确、友好的服务。
- 通过全面理解信息,`LightRAG` 能够处理各种类型的查询,无论是具体问题还是抽象概念。
3. 知识管理系统:
- 在知识管理系统中,`LightRAG` 可以高效地管理和检索知识,帮助用户快速找到所需信息。
- 通过增量更新算法,`LightRAG` 能够及时整合新知识,保持系统的最新状态。
4. 科研辅助:
- 在科研辅助中,`LightRAG` 可以帮助研究人员快速查找相关文献和数据,提高科研效率。
- 通过图结构索引,`LightRAG` 能够捕捉文献之间的关联,提供更全面的科研支持。
`LightRAG` 是一种先进的检索增强生成系统,通过整合图结构索引和双层检索机制,显著提升了大型语言模型在信息检索中的准确性和效率。无论是在搜索引擎、智能客服、知识管理系统还是科研辅助中,`LightRAG` 都能够提供高质量的检索和生成服务,满足多样化的应用需求。
项目具体介绍网上资料很多,这里不再赘述。也可参考:https://arxiv.org/abs/2410.05779
及https://sites.google.com/view/chaoh。
下面就开始我们的旅程,使用本地ollama服务器,实现LightRAG。
LigthRag已经提供ollama本地llm接口使用示例,代码文件为./examples/lightrag_ollama_demo.py。下面我们就进行代码分步解读:
一、导入必要的库
import os
import logging
from lightrag import LightRAG, QueryParam
from lightrag.llm import ollama_model_complete, ollama_embedding
from lightrag.utils import EmbeddingFunc
# 导入必要的库
import nest_asyncio
# 应用 nest_asyncio
nest_asyncio.apply()
二、创建工作目录
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参数,启动Rag读取文件
根据我们本地ollama服务的地址和模型名称,填写下面信息即可。这里用到两个模型mistral是llm模型,nomice-embed-text是嵌入式模型,负责将文档转换为嵌入式向量。
注意:我们进行rag的目标文件book.txt,在文章的最后提供
rag = LightRAG(working_dir=WORKING_DIR,llm_model_func=ollama_model_complete,llm_model_name="mistral:latest",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"),),
)#!curl https://raw.githubusercontent.com/gusye1234/nano-graphrag/main/tests/mock_data.txt > ./book.txt
i=0
with open("./book.txt", "r", encoding="utf-8") as f:rag.insert(f.read())print("完成行数:", ++i)
四、执行查询
示例提供了四种查询:1、普通查询、2、本地查询、3、全局查询、4、混合查询。
对于负责的任务,全局和混合查询准确率较高。
# 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"))
)
五、使用在线收费llm模型+本地ollama_embedding模型的模式
由于本地服务器性能的原因,我使用本地llm模型运行几个小时都未能完成rag数据加载任务。不得已采用阿里源收费的魔塔在线模型服务,结合本地ollama_embedding模型的方式进行Rag数据读取,完美运行通过。下面是代码修改过程。
1)定义llm_model_func函数:
api_key和qwen2-72b-instruct需要填写您自己的模型名称及key值,其他的可以不需要调整。
from lightrag.llm import openai_complete_if_cacheasync def llm_model_func(prompt, system_prompt=None, history_messages=[], **kwargs) -> str:return await openai_complete_if_cache("qwen2-72b-instruct", # LLM模型名称prompt, system_prompt=system_prompt, history_messages=history_messages,api_key="sk-xxxxxxxx", # LLM_api_keybase_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # LLM_url**kwargs)
2)修改前面的第三步 "三、配置Rag参数,启动Rag读取文件",如下:
rag = LightRAG(working_dir=WORKING_DIR,llm_model_func=llm_model_func,
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"),),
)i=0
with open("./book.txt", "r", encoding="utf-8") as f:rag.insert(f.read())print("完成行数:", ++i)
执行日志:
INFO:lightrag:Logger initialized for working directory: ./dickens
INFO:lightrag:Load KV llm_response_cache with 0 data
INFO:lightrag:Load KV full_docs with 0 data
INFO:lightrag:Load KV text_chunks with 0 data
INFO:lightrag:Loaded graph from ./dickens/graph_chunk_entity_relation.graphml with 0 nodes, 0 edges
INFO:nano-vectordb:Load (0, 768) data
INFO:nano-vectordb:Init {'embedding_dim': 768, 'metric': 'cosine', 'storage_file': './dickens/vdb_entities.json'} 0 data
INFO:nano-vectordb:Load (0, 768) data
INFO:nano-vectordb:Init {'embedding_dim': 768, 'metric': 'cosine', 'storage_file': './dickens/vdb_relationships.json'} 0 data
INFO:nano-vectordb:Load (2, 768) data
INFO:nano-vectordb:Init {'embedding_dim': 768, 'metric': 'cosine', 'storage_file': './dickens/vdb_chunks.json'} 2 data
INFO:lightrag:[New Docs] inserting 1 docs
INFO:lightrag:[New Chunks] inserting 2 chunks
INFO:lightrag:Inserting 2 vectors to chunks
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:lightrag:[Entity Extraction]...
INFO:httpx:HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions "HTTP/1.1 200 OK"
⠙ Processed 1 chunks, 17 entities(duplicated), 0 relations(duplicated)
INFO:httpx:HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions "HTTP/1.1 200 OK"
⠹ Processed 2 chunks, 49 entities(duplicated), 4 relations(duplicated)
INFO:lightrag:Inserting 46 vectors to entitiesINFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:lightrag:Inserting 4 vectors to relationships
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK"
INFO:lightrag:Writing graph with 46 nodes, 4 edges
完成行数: 0
六、关系视图可视化:
python graph_visual_with_html.py
七、提问测试
下面我们就开始进行提问了
1、普通查询
# Perform naive search
if 1:print(rag.query("根据提供的材料,给我查找所有关于股票市场相关信息示例?", param=QueryParam(mode="naive")))
从返回的日志可以看出,回答的内容是模型自己的知识库,并非我们文档的内容。
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK" INFO:lightrag:Truncate 2 to 2 chunks The provided documents contain detailed information about stock market summaries from both the Shanghai Stock Exchange (SSE) and the Shenzhen Stock Exchange (SZSE). Below is an overview of the data available:### Shanghai Stock Exchange (SSE)The SSE provides a summary of the stock market which includes the following data points:- **Circulating Share Capital**: The total number of shares that are freely tradable on the market. - **Total Market Value**: The total value of all listed stocks. - **Average P/E Ratio**: The average price-to-earnings ratio of all listed companies. - **Number of Listed Companies**: Total number of companies listed on the exchange. - **Listed Stocks**: Total number of stocks listed on the exchange. - **Circulating Market Value**: The total value of the circulating share capital. - **Report Time**: The date when the report was published. - **Total Shares**: The total number of shares issued by all listed companies.### Shenzhen Stock Exchange (SZSE)For the SZSE, there is a more detailed breakdown by security category:- **Stocks**: Total number of stocks listed, their trading volume, total market value, and circulating market value. - **Main Board A-Shares**: Specific data for A-shares listed on the main board. - **Main Board B-Shares**: Specific data for B-shares listed on the main board. - **Small-Medium Enterprises Board**: Data for stocks listed on the SME board. - **Growth Enterprise Market (GEM) A-Shares**: Data for A-shares listed on the GEM. - **Funds**: Trading volume and total market value of funds listed on the exchange. - **ETFs**: Data specific to Exchange-Traded Funds. - **LOFs**: Data for Listed Open-Ended Funds. - **Closed-End Funds**: Information about closed-end funds. - **Graded Funds**: Details about graded investment funds. - **Bonds**: Total trading volume and total market value of bonds. - **Bond Spot**: Trading volume and total market value of bond spot transactions. - **Bond Repurchase**: Trading volume for bond repurchase agreements. - **ABS**: Trading volume and total market value of Asset-Backed Securities. - **Options**: Information regarding options traded on the exchange.These summaries can be accessed using the `akshare` library in Python by calling the `stock_sse_summary()` function for the SSE data and the `stock_szse_summary(date)` function for the SZSE data, specifying the date for the latter if needed. The data provided offers insights into the overall health and activity of the stock markets in China, including metrics such as trading volumes, market values, and the number of listed securities across different categories
2、本地查询
if 1:# Perform local searchprint(rag.query("根据提供的材料,给我查找所有关于股票市场相关信息示例?", param=QueryParam(mode="local")))
从返回的日志可以看出,回答的内容是模型自己的知识库,也并非我们文档的内容,如下:
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK" INFO:lightrag:Local query uses 46 entites, 4 relations, 2 text units The provided materials offer comprehensive insights into the stock markets, specifically focusing on the Shanghai and Shenzhen Stock Exchanges in China. Below is a detailed summary of the data available, categorized into sections for clarity:### Shanghai Stock Exchange (SSE)The SSE provides a summary of the overall market conditions through the `stock_sse_summary` function accessible via the AKShare library. This function retrieves recent trading day data regarding various aspects of the stock market. Key information includes:- **Circulating Share Volume**: The total number of shares that are freely tradable on the market. - **Total Market Capitalization**: The aggregate market value of all listed companies. - **Average Price-to-Earnings Ratio**: An indicator of the market's valuation level. - **Number of Listed Companies**: Total count of companies listed on the exchange. - **Listed Stocks**: The number of stocks currently traded on the exchange. - **Floating Market Value**: The market value of freely tradable shares. - **Report Date**: The date on which the data was reported.For instance, as of December 30, 2021, the SSE reported: - A circulating share volume of 40,403.47 billion, - A total market capitalization of 516,714.68 billion yuan, - An average P/E ratio of 17.92, - 2,036 listed companies, - 2,078 listed stocks, - A floating market value of 432,772.13 billion yuan, - And a total share volume of 46,234.03 billion.### Shenzhen Stock Exchange (SZSE)The SZSE offers a detailed breakdown of statistics on different securities categories through the `stock_szse_summary` function. This function requires a specific date as an input parameter and returns data on:- **Security Categories**: Various types of securities listed on the exchange. - **Quantity**: The number of securities listed. - **Trading Volume**: The total amount of money exchanged in transactions. - **Total Market Capitalization**: The total value of all securities. - **Floating Market Value**: The market value of freely tradable securities.As an example, on June 19, 2020, the SZSE reported: - 2,284 listed securities, - A trading volume of 464.7749 billion yuan, - A total market capitalization of 27.06514 trillion yuan, - A floating market value of 21.04546 trillion yuan.### Specific Securities CategoriesThe SZSE further categorizes the securities into distinct groups, providing detailed statistics for each category:- **Main Board A-shares**: 460 listed securities with a trading volume of 97.7595 billion yuan, a total market capitalization of 7.864787 trillion yuan, and a floating market value of 6.94399 trillion yuan. - **Main Board B-shares**: 46 listed securities with a trading volume of 86.2682 million yuan, a total market capitalization of 47.59658 billion yuan, and a floating market value of 47.06385 billion yuan. - **Small and Medium Enterprises Board**: 960 listed securities with a trading volume of 201.3526 billion yuan, a total market capitalization of 1.130741 trillion yuan, and a floating market value of 866.9555 billion yuan. - **Growth Enterprise Market (GEM) A-shares**: 818 listed securities with a trading volume of 165.5765 billion yuan, a total market capitalization of 7.845345 trillion yuan, and a floating market value of 5.384854 trillion yuan. - **Investment Funds**: 551 listed securities with a trading volume of 13.62524 billion yuan, a total market capitalization of 241.7277 billion yuan, and a floating market value of 241.7277 billion yuan. - **Exchange-Traded Funds (ETFs)**: 100 listed securities with a trading volume of 11.65436 billion yuan, a total market capitalization of 162.8294 billion yuan, and a floating market value of 162.8294 billion yuan. - **Listed Open-Ended Funds (LOFs)**: 250 listed securities with a trading volume of 733.5768 million yuan, a total market capitalization of 40.43156 billion yuan, and a floating market value of 40.43156 billion yuan. - **Closed-End Funds**: 1 listed security with a trading volume of 552,757 yuan, a total market capitalization of 762.244 million yuan, and a floating market value of 762.244 million yuan. - **Structured Funds (Graded Funds)**: 200 listed securities with a trading volume of 1.236746 billion yuan, a total market capitalization of 37.70451 billion yuan, and a floating market value of 37.70451 billion yuan. - **Bonds**: 7,174 listed securities with a trading volume of 137.1389 billion yuan. - **Physical Bonds**: 6,599 listed securities with a trading volume of 29.11357 billion yuan, a total market capitalization of 36.83881 trillion yuan, and a floating market value of 1.823072 trillion yuan. - **Bond Repurchase Agreements**: 13 listed securities with a trading volume of 105.4592 billion yuan. - **Asset-Backed Securities (ABS)**: 562 listed securities with a trading volume of 2.566134 billion yuan, a total market capitalization of 484.9642 billion yuan, and a floating market value of 484.9642 billion yuan. - **Options**: 108 listed securities with a trading volume of 244.156 million yuan.These summaries provide valuable insights into the health and dynamics of the Chinese stock markets, including the size, liquidity, and composition of the securities listed on these exchanges.所提供的材料提供了对股票市场的全面见解,特别是专注于中国的上海和深圳证券交易所。以下是可用数据的详细总结,为清晰起见,分为几节:#上海证券交易所上交所通过AKShare库中的“stock_sse_summary”函数提供整体市场状况的摘要。此函数检索有关股票市场各个方面的最近交易日数据。主要信息包括:- ** 流通股数量 **:指市场上可自由交易的股份总数。 - ** 总市值 **:所有上市公司的总市值。 - ** 平均市盈率 **:市场估值水平的指标。 - ** 上市公司数量 **:在交易所上市的公司总数。 - ** 上市股票 **:目前在交易所交易的股票数量。 - ** 浮动市值 **:自由流通股的市值。 - ** 上报日期 **:数据上报的日期。例如,截至2021年12月30日,上交所报告: - 流通股量404034.7亿股, - 总市值516714.68亿元, - 平均市盈率为17.92倍, - 2,036家上市公司, - 2,078只上市股票, - 浮市值432772.13亿元, - 总发行量为462340.3亿股。###深圳证券交易所深交所通过“stock_szse_summary”功能,提供不同证券类别的详细统计数据。该函数需要特定日期作为输入参数,并返回以下数据:- ** 证券类别 **:指在交易所上市的各类证券。 - ** 数量 **:列出的证券数量。 - ** 交易量 **:交易的总金额。 - ** 总市值 **:所有证券的总价值。 - ** 浮动市值 **:可自由交易证券的市值。例如,2020年6月19日,深交所报告: - 2,284种上市证券, - 成交量4647.49亿元, - 总市值270.6514万亿元, - 浮市值210.4546亿元。#具体证券类别深交所进一步将证券分类为不同的组别,并为每个类别提供详细的统计数据:- ** 主板A股 **:上市证券460只,成交量9775.95亿元,总市值78647.87亿元,流通市值6943.99亿元。 - ** 主板B股 **:上市证券46只,成交量8626.82万元,总市值47596.58亿元,流通市值47063.85亿元。 - ** 中小企业板 **:上市证券960只,交易量20135.26亿元,总市值11307.41亿元,流通市值86695.55亿元。 - ** 创业板A股 **:上市证券818只,成交量16557.65亿元,总市值78453.45亿元,流通市值53848.54亿元。 - ** 投资基金 **:上市证券551只,成交量13625.24亿元,总市值24172.77亿元,流通市值24172.77亿元。 - ** 交易所交易基金(ETF)**:上市证券100只,交易量11654.36亿元,总市值16282.94亿元,浮动市值16282.94亿元。 - ** 上市开放式基金(LOFs)**:上市证券250只,交易量73357.68万元,总市值40431.56亿元,浮动市值40431.56亿元。 - ** 封闭式基金 **:1只上市证券,成交量552,757元,总市值76224. 40万元,浮动市值76224. 40万元。 - ** 结构化基金(分级基金)**:上市证券200只,交易量12367.46亿元,总市值37704.51亿元,浮动市值37704.51亿元。 - ** 债券 **:上市证券7,174只,成交量13713.89亿元。 - ** 实物债券 **:上市证券6,599只,成交量2911357亿元,总市值3683881亿元,流通市值1823072亿元。 - ** 债券回购协议 **:13只上市证券,成交量10545.92亿元。 - ** 资产支持证券(ABS)**:上市证券562只,交易量25661.34亿元,总市值48496.42亿元,浮动市值48496.42亿元。 - ** 期权 **:上市证券108只,成交量24415.6万元。这些摘要为中国股市的健康和动态提供了宝贵的见解,包括在这些交易所上市的证券的规模,流动性和构成。
3、全局查询、
if 1:# Perform global searchprint(rag.query("根据提供的材料,给我查找所有关于股票市场相关信息示例?", param=QueryParam(mode="global")))
全局查询模式下,模型能完美识别我们的问题,并根据文档提供我们想要的答案。这次回答是成功的!!
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK" INFO:lightrag:Global query uses 5 entites, 4 relations, 1 text units INFO:httpx:HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions "HTTP/1.1 200 OK" ### 股票市场信息概览#### 上海证券交易所(SSE)市场总貌**接口**: `stock_sse_summary`- **目标地址**: http://www.sse.com.cn/market/stockdata/statistic/ - **描述**: 提供上海证券交易所的市场总貌数据,包括流通股本、总市值、平均市盈率等关键指标。 - **输入参数**: 无需输入参数。 - **输出参数**:- 项目: 包括主板、科创板等不同板块的统计数据。- 股票、科创板、主板: 分别展示各板块的具体数据,如流通股本、总市值和平均市盈率等。**数据示例**: ```markdown项目 股票 科创板 主板 0 流通股本 40403.47 413.63 39989.84 1 总市值 516714.68 55719.6 460995.09 2 平均市盈率 17.92 71.0 16.51 3 上市公司 2036 377 1659 4 上市股票 2078 377 1701 5 流通市值 432772.13 22274.3 410497.83 6 报告时间 20211230 20211230 20211230 8 总股本 46234.03 1211.5 45022.54 ```#### 深圳证券交易所(SZSE)市场总貌**接口**: `stock_szse_summary`- **目标地址**: http://www.szse.cn/market/overview/index.html - **描述**: 提供深圳证券交易所市场总貌数据,按证券类别统计,包括股票、债券、基金等多种类型。 - **输入参数**: - `date`: 需要指定日期,格式为"YYYYMMDD"。当前交易日的数据需在交易所收盘后获取。 - **输出参数**:- 证券类别: 包括股票、主板A股、主板B股、中小板等。- 数量: 各类证券的数量,单位为只。- 成交金额、总市值、流通市值: 相关的金融数据,单位分别为元。**数据示例**: ```markdown证券类别 数量 成交金额 总市值 流通市值 0 股票 2284 4.647749e+11 2.706514e+13 2.104546e+13 1 主板A股 460 9.775950e+10 7.864787e+12 6.943990e+12 2 主板B股 46 8.626816e+07 4.759658e+10 4.706385e+10 3 中小板 960 2.013526e+11 1.130741e+13 8.669555e+12 4 创业板A股 818 1.655765e+11 7.845345e+12 5.384854e+12 5 基金 551 1.362524e+10 2.417277e+11 2.417277e+11 6 ETF 100 1.165436e+10 1.628294e+11 1.628294e+11 7 LOF 250 7.335768e+08 4.043156e+10 4.043156e+10 8 封闭式基金 1 5.527571e+05 7.622440e+08 7.622440e+08 9 分级基金 200 1.236746e+09 3.770451e+10 3.770451e+10 10 债券 7174 1.371389e+11 NaN NaN 11 债券现券 6599 2.911357e+10 3.683881e+13 1.823072e+12 12 债券回购 13 1.054592e+11 NaN NaN 13 ABS 562 2.566134e+09 4.849642e+11 4.849642e+11 14 期权 ```### 结论以上信息展示了通过`AKShare`库访问上海证券交易所和深圳证券交易所的市场总貌数据的方法及数据示例。这些数据覆盖了流通股本、总市值、平均市盈率以及各类证券的详细统计数据,对于分析中国股市的整体状况提供了全面的视角。
4、混合查询
if 1:# Perform hybrid searchprint(rag.query("根据提供的材料,给我查找所有关于股票市场相关信息示例?", param=QueryParam(mode="hybrid")))
混合查询模式下,模型能完美识别我们的问题,并根据文档提供我们想要的答案。回答的内容根据简洁,明了。这次回答也是成功的!
INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK" INFO:lightrag:Local query uses 46 entites, 4 relations, 2 text units INFO:httpx:HTTP Request: POST http://localhost:11434/api/embeddings "HTTP/1.1 200 OK" INFO:lightrag:Global query uses 5 entites, 4 relations, 1 text units INFO:httpx:HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions "HTTP/1.1 200 OK" ## 股票市场信息概览### AKShare与股票市场数据的集成AKShare是一个强大的组织,它提供了一个库来访问股票市场的数据,包括来自上海证券交易所和深圳证券交易所的信息。通过其API,AKShare能够从这两个主要的金融市场获取和检索数据。### 上海证券交易所与AKShare的集成上海证券交易所是一个重要的金融平台,它不仅提供了股票交易的场所,还详细记录了市场上的各种统计数据,如上市公司的概况、交易量和市值等。AKShare通过`stock_sse_summary`函数与上海证券交易所进行数据交互,这个事件代表了从上海证券交易所获取市场总貌数据的过程。这包括了市场资本化水平、平均市盈率以及上市公司的数量等关键指标。### 深圳证券交易所与AKShare的集成同样地,深圳证券交易所也是一个活跃的金融市场,它涵盖了多种证券类别,如股票、债券和基金,并提供了详细的市场数据。AKShare通过`stock_szse_summary`事件从深圳证券交易所获取这些数据,该事件涉及从深圳证券交易所提取总结性数据,涵盖了各类证券的数量、交易量和市场价值等重要统计信息。### 数据获取与分析上海证券交易所和深圳证券交易所通过AKShare的API向用户提供数据。`stock_sse_summary`和`stock_szse_summary`事件分别代表了从两个交易所获取数据的过程。这些数据对于理解市场动态、分析投资机会以及进行市场研究至关重要。### 实时行情数据示例以下是通过AKShare从上海证券交易所获取的实时行情数据的一个示例:| 名称 | 类型 | 描述 | |----------|--------|------------| | 项目 | object | - | | 股票 | object | - | | 科创板 | object | - | | 主板 | object | - |请注意,上述示例中的“-”表示具体描述未在提供的材料中明确给出。实际上,这些字段可能包含了具体的数值和统计信息,如股票价格、成交量、科创板的公司数量或主板的市场总值等。总之,AKShare与上海证券交易所和深圳证券交易所之间的数据交互为用户提供了深入洞察中国股票市场的工具,帮助投资者和分析师更好地理解和利用市场信息。
附录:book.txt文档:
## [AKShare](https://github.com/akfamily/akshare) 股票数据### A股#### 股票市场总貌##### 上海证券交易所接口: stock_sse_summary目标地址: http://www.sse.com.cn/market/stockdata/statistic/描述: 上海证券交易所-股票数据总貌限量: 单次返回最近交易日的股票数据总貌(当前交易日的数据需要交易所收盘后统计)输入参数| 名称 | 类型 | 描述 |
|-----|-----|-----|
| - | - | - |输出参数-实时行情数据| 名称 | 类型 | 描述 |
|-----|--------|-----|
| 项目 | object | - |
| 股票 | object | - |
| 科创板 | object | - |
| 主板 | object | - |接口示例```python
import akshare as akstock_sse_summary_df = ak.stock_sse_summary()
print(stock_sse_summary_df)
```数据示例```项目 股票 科创板 主板
0 流通股本 40403.47 413.63 39989.84
1 总市值 516714.68 55719.6 460995.09
2 平均市盈率 17.92 71.0 16.51
3 上市公司 2036 377 1659
4 上市股票 2078 377 1701
5 流通市值 432772.13 22274.3 410497.83
6 报告时间 20211230 20211230 20211230
8 总股本 46234.03 1211.5 45022.54
```##### 深圳证券交易所###### 证券类别统计接口: stock_szse_summary目标地址: http://www.szse.cn/market/overview/index.html描述: 深圳证券交易所-市场总貌-证券类别统计限量: 单次返回指定 date 的市场总貌数据-证券类别统计(当前交易日的数据需要交易所收盘后统计)输入参数| 名称 | 类型 | 描述 |
|------|-----|-------------------------------------|
| date | str | date="20200619"; 当前交易日的数据需要交易所收盘后统计 |输出参数| 名称 | 类型 | 描述 |
|------|---------|---------|
| 证券类别 | object | - |
| 数量 | int64 | 注意单位: 只 |
| 成交金额 | float64 | 注意单位: 元 |
| 总市值 | float64 | - |
| 流通市值 | float64 | - |接口示例```python
import akshare as akstock_szse_summary_df = ak.stock_szse_summary(date="20200619")
print(stock_szse_summary_df)
```数据示例```证券类别 数量 成交金额 总市值 流通市值
0 股票 2284 4.647749e+11 2.706514e+13 2.104546e+13
1 主板A股 460 9.775950e+10 7.864787e+12 6.943990e+12
2 主板B股 46 8.626816e+07 4.759658e+10 4.706385e+10
3 中小板 960 2.013526e+11 1.130741e+13 8.669555e+12
4 创业板A股 818 1.655765e+11 7.845345e+12 5.384854e+12
5 基金 551 1.362524e+10 2.417277e+11 2.417277e+11
6 ETF 100 1.165436e+10 1.628294e+11 1.628294e+11
7 LOF 250 7.335768e+08 4.043156e+10 4.043156e+10
8 封闭式基金 1 5.527571e+05 7.622440e+08 7.622440e+08
9 分级基金 200 1.236746e+09 3.770451e+10 3.770451e+10
10 债券 7174 1.371389e+11 NaN NaN
11 债券现券 6599 2.911357e+10 3.683881e+13 1.823072e+12
12 债券回购 13 1.054592e+11 NaN NaN
13 ABS 562 2.566134e+09 4.849642e+11 4.849642e+11
14 期权 108 2.441560e+08 NaN NaN
```
相关文章:

LightRAG开源了…结合本地ollama实现股票数据接口Akshare智能问答
LightRAG是由香港大学研究团队推出的一种检索增强生成(Retrieval-Augmented Generation, RAG)系统。该系统通过整合图结构索引和双层检索机制,显著提升了大型语言模型在信息检索中的准确性和效率。LightRAG 不仅能够捕捉实体间的复杂依赖关系…...

【PCB设计】AD16教程:分配位号
1、前提条件 确保已经基本画完原理图 2、点击【Tools-Annotate Schematics】 3、依次点击【Reset All】、【Update Changes Lise】、【Close】 最后位号就被自动分配好了...

ElasticSearch7.x入门教程之索引概念和基础操作(三)
文章目录 前言一、索引基本概念二、索引基本使用elasticsearch-head插件Kibana使用 总结 前言 要想熟悉使用ES的索引,则必须理解索引相关的概念,尤其是在工作当中。 在此记录,方便开展工作。 一、索引基本概念 尽量以通俗的话语。 1、集群…...

Python后端flask框架接收zip压缩包方法
一、用base64编码发送,以及接收 import base64 import io import zipfile from flask import request, jsonifydef unzip_and_find_png(zip_data):# 使用 BytesIO 在内存中处理 zip 数据with zipfile.ZipFile(io.BytesIO(zip_data), r) as zip_ref:extracted_paths…...

机器学习中数据集Upsampling和Downsampling是什么意思?中英文介绍
对GPT4o大模型的Prompt如下: Datasets marked with ↓ are downsampled from their original datasets, datasets marked with ↑ are upsampled.这里的上采样和下采样是什么意思 内容援引自:paper (https://allenai.org/papers/tulu-3-repor…...

浏览器控制台中使用ajax下载文件(没有postman等情况下)
有时候,可能电脑里面没有postman(比如内网),然后又需要导出一些文件,前端又没有提供相应的功能(比如循环调用导出等),这时候我们就可以通过在控制台写代码的方式来实现了。这个还是在…...

完全二叉树的基本操作(顺序存储)
#include<iostream> #include<math.h> using namespace std;#define MaxSize 100 struct TreeNode {int value;bool isEmpty;//判断该节点是否为空 }t[MaxSize];/** *定义一个长度位MaxSize的数组,按照从上到下, *从左到右的方式依次存储完全…...

【HTTP】http与https
http与https的关系 应用层协议: http(HyperText Transfer Protocol)超文本传输协议; https(Hypertext Transfer Protocol Secure)超文本传输安全协议; 传输层协议:TCP(Tr…...

【Git多人开发与协作之团队的环境搭建】
Git多人开发与协作之团队的环境搭建 新的改变1. Git 的用途2. 分支的概念与类型3. HEAD 和分支指针如何查看 HEAD 指向的位置: 4. 常见的 Git 操作5. 常见问题与解决方法总结GitHub 项目获取实操在新电脑上运行 Git1. 安装 Git2. 配置用户名和邮箱3.配置 Git 和 SSH…...

java基础概念36:正则表达式1
一、正则表达式的作用 作用一:校验字符串是否满足规则;作用二:在一段文本中查找满足要求的内容。——爬虫 二、正则表达式 2-1、字符类 示例: public static void main(String[] args) {System.out.println("a".matc…...

java实现小程序接口返回Base64图片
文章目录 引言I java 接口返回Base64图片接口设计获取验证码图片-base64字符串获取验证码图片-二进制流arraybufferII 小程序端代码过期代码: 显示文件流图片(arraybuffer)知识扩展:微信小程序下载后端返回的文件流引言 场景: 图形验证码 背景: 接口返回arraybuffer的格式…...

网络编程并发服务器的应用
作业2:完成局域网CS模型,局域网内一个服务器,多个客户端连接一个服务器,完成局域网聊天(select函数,poll函数,完成TCP并发服务器)。 poll函数应用: 服务器部分代码&…...

数据结构——停车场管理问题
目录 1、问题描述2、逐步分析1)涉及操作2)代码实现 3、代码整合 1、问题描述 1、题目 设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可供汽车进出。汽车在停车场内按车辆到达时间的先后顺序,依次由北向南排列&#x…...

道品智能科技移动式水肥一体机:农业灌溉施肥的革新之选
在现代农业的发展进程中,科技的力量正日益凸显。其中,移动式水肥一体机以其独特的可移动性、智能化以及实现水肥一体化的卓越性能,成为了农业领域的一颗璀璨新星。它不仅改变了传统的农业灌溉施肥方式,更为农业生产带来了高效、精…...

AI实习--常用的Linux命令
一、基础命令 1. 切换到根目录。 cd ~ 2. 返回上一级目录。 cd .. 3. 查看当前目录下包括哪些文件和文件夹。 ls 4. 查看当前路径。 pwd 5. 将文件或文件夹剪切到目标目录下。 mv 文件所在路径 目标路径 6. 查看文本文件内容。 cat 文本文件名 7. 创建文件或文件夹…...

Python学习指南 + 谷歌浏览器如何安装插件
找往期文章包括但不限于本期文章中不懂的知识点: 个人主页:我要学编程(ಥ_ಥ)-CSDN博客 所属专栏: Python 目录 前言 Python 官方文档的使用 谷歌浏览器中如何安装插件 前言 在学习Python时,我们可能会出现这样的困惑&#x…...

研0找实习【学nlp】15---我的后续,总结(暂时性完结)
当下进展成果: nlptransformerpytorchhuggingfacebert简历环境配置表情识别文本分类 断更了快1个月,2个礼拜找实习,1个礼拜伤心,1个礼拜想我要干什么…… 承认自己的才疏学浅,了解了leetcode,和老师商量了…...

kylin麒麟银河桌面版操作系统安装部署
本文主要描述kylin麒麟银河桌面版操作系统的安装,该操作系统的安装源文件可以从kylin麒麟银河官方网站上下载,商业版本需要申请试用,开源版本可以直接下载使用。 如上所示,x86芯片处理器架构的请下载INTEL版本,华为海思…...

MyBatis插件原理及应用
🎮 作者主页:点击 🎁 完整专栏和代码:点击 🏡 博客主页:点击 文章目录 介绍<plugins>标签解析拦截器链的工作原理插件的应用场景MyBatis插件应用的四个组件InterceptorChain和Interceptor MyBatis框架…...

[M最短路] lc743. 网络延迟时间(spfa最短路+单源最短路)
文章目录 1. 题目来源2. 题目解析 1. 题目来源 链接:743. 网络延迟时间 相关链接: [图最短路模板] 五大最短路常用模板) 2. 题目解析 怎么讲呢,挺抽象的…很久没写最短路算法了。反正也是写出来了,但脱离了模板,把…...

MySQL 中的锁
MySQL 中的锁:全面解析与应用指南 在 MySQL 数据库的复杂世界里,锁是确保数据一致性、完整性以及并发控制的关键机制。无论是简单的小型应用还是复杂的企业级系统,深入理解 MySQL 中的锁对于优化数据库性能、避免数据冲突和错误都具有至关重要…...

【动手学电机驱动】STM32-FOC(8)MCSDK Profiler 电机参数辨识
STM32-FOC(1)STM32 电机控制的软件开发环境 STM32-FOC(2)STM32 导入和创建项目 STM32-FOC(3)STM32 三路互补 PWM 输出 STM32-FOC(4)IHM03 电机控制套件介绍 STM32-FOC(5&…...

【C++11】尽显锋芒
(续) 一、可变参数模板 C11支持可变参数模板,也就是说支持可变数量参数的函数模板和类模板,可变数目的参数被称 为参数包,存在两种参数包:模板参数包,表示零或多个模板参数;函数参数包:表示零…...

掌握控制流的艺术:Go语言中的if、for和switch语句
标题:掌握控制流的艺术:Go语言中的if、for和switch语句 在Go语言的编程世界中,控制流语句是构建程序逻辑的基石。if语句、for循环和switch语句是我们最常用的控制流工具,它们让我们能够根据不同的条件执行不同的代码块。本文将深入探讨这些语句的使用方法、技术细节和实际…...

飞书会话消息左右排列
飞书会话消息左右排列 1. 飞书登录后,点击头像,弹出菜单有个按钮设置 2. 3....

.net 支持跨平台(桌面)系列技术汇总
1. 首先微软老大哥的.net core 。 .NET Core 是微软开发的一个跨平台、高性能的开源框架,用于构建云和互联网连接的新型应用。 它允许开发者在 Windows、macOS 和 Linux 上使用喜爱的开发工具进行开发,并支持部署到云或本地环境。 .NET Core 是对 .NET …...

springboot 静态资源访问
最近在学习springboot,在学习中一个静态资源访问,难道了我三天,在网上找了很多的资料,又是配置,又是重写WebMvcConfigurationSupport,因为以前没有接触,本来很简单的事情走了很多弯路࿰…...

【linux学习指南】初识Linux进程信号与使用
文章目录 📝信号快速认识📶⽣活⻆度的信号📶 技术应⽤⻆度的信号🌉 前台进程(键盘)🌉⼀个系统函数 📶信号概念📶查看信号 🌠 信号处理🌉 忽略此信…...

L1G1000 书生大模型全链路开源开放体系笔记
关卡任务 观看本关卡视频后,写一篇关于书生大模型全链路开源开放体系的笔记。 视频链接:【书生浦语大模型全链路开源体系】 : 书生浦语大模型开源开放体系_哔哩哔哩_bilibili 书生大模型全链路开源开放体系笔记 在人工智能领域,大模型的…...

亚信安全与飞书达成深度合作
近日,亚信安全联合飞书举办的“走近先进”系列活动正式走进亚信。活动以“安全护航信息化 共筑数字未来路”为主题,吸引了众多数字化转型前沿企业的近百位领导参会。作为“走近先进”系列的第二场活动,本场活动更加深入挖掘了数字化转型的基础…...