当前位置:   article > 正文

借助知识图谱和Llama-Index实现基于大模型的RAG

借助知识图谱和Llama-Index实现基于大模型的RAG

背景

幻觉是在处理大型语言模型(LLMs)时常见的问题。LLMs生成流畅连贯的文本,但经常产生不准确或不一致的信息。防止LLMs中出现幻觉的一种方法是使用外部知识源,如提供事实信息的数据库或知识图谱。

矢量数据库和知识图谱使用不同的方法来存储和表示数据。矢量数据库适合基于相似性的操作,知识图谱旨在捕捉和分析复杂的关系和依赖关系。

对于LLM中的幻觉问题,知识图谱是一个比向量数据库更好的解决方案。知识图谱为LLM提供了更准确、相关、多样化、有趣、逻辑和一致的信息。因此,使用知识图谱可以减少LLM中的幻觉,使其在生成准确和真实的文本时更加可靠。但关键是文档需要清楚地展示关系,否则知识图谱将无法捕捉到它。

向量数据库

向量数据库是一组高维向量的集合,用于表示实体或概念,例如单词、短语或文档。向量数据库可以根据实体或概念的向量表示来度量它们之间的相似性或关联性。

举个例子,向量数据库可以告诉你“巴黎”和“法国”比“巴黎”和“德国”更相关,基于它们的向量距离。

知识图谱

知识图谱是一组节点和边,用于表示实体或概念以及它们之间的关系,例如事实、属性或类别。知识图谱可以根据节点和边的属性来查询或推断不同实体或概念的事实信息。

举个例子,知识图谱可以告诉你“巴黎”是“法国”的首都,基于它们的边标签。

知识图谱组件

顶点/节点:表示知识领域中的实体或对象。每个节点对应一个唯一的实体,并由唯一的标识符进行标识。例如,在关于Chennai Kings的知识图谱中,节点可以具有诸如“Philadelphia Phillies”和“Major League Cricket”这样的值。

边:表示两个节点之间的关系。例如,一条“compete in”的边可以将“Chennai Kings”节点连接到“Major League Cricket”节点。

知识图谱中的基本数据单元

三元组是图中的基本数据单元。它由三个部分组成:

主语:三元组所关于的节点。

宾语:关系指向的节点。

谓语:主语和宾语之间的关系。

在以下三元组示例中,“Chennai Kings”是主语,“compete in”是谓语,“Major League Cricket”是宾语。

(Chennai Kings) — [compete in]->(Major League Cricket)

知识图谱数据库可以通过存储三元组来高效地存储和查询复杂的图数据。

查询图数据库

查询涉及遍历图结构并根据特定标准检索节点、关系或模式。下面是一个简单的示例,展示了如何查询图数据库:假设你有一个代表社交网络的图数据库,其中用户是节点,而它们的关系(例如友谊)由连接节点的边表示。你想要找到给定用户的朋友圈(共同的连接)。

  1. 从参考用户开始:在图数据库中,通过查询特定的用户标识符或其他相关标准来识别代表参考用户的节点。
  2. 遍历图:使用图形查询语言(如Neo4j中使用的Cypher或Gremlin)从参考用户节点遍历图。编写一个查询,指定要探索的模式或关系。在这种情况下,您想要找到朋友的朋友。示例Cypher查询:MATCH (:User {userId: ‘referenceUser’})-[:FRIEND]->()-[:FRIEND]->(fof:User) RETURN fof这个查询从参考用户开始,沿着FRIEND关系找到另一个节点(朋友),然后再沿着另一个FRIEND关系找到朋友的朋友(fof)。
  3. 检索结果:在图数据库上执行查询,根据查询模式检索出相应的节点(朋友的朋友)。如果需要,还可以获取检索到的节点的特定属性或附加信息。
  4. 呈现结果:将检索到的朋友的朋友显示给用户或按照需求进一步处理数据。这些信息可以用于建议、网络分析或其他相关目的。

图数据库提供了更高级查询功能,包括过滤、聚合和复杂模式匹配。具体的查询语言和语法可能有所不同,但总体过程涉及遍历图结构以检索与所需条件匹配的节点和关系。

查询向量数据库

通常涉及搜索相似向量或根据特定条件检索向量。以下是查询向量数据库的简单示例:假设你有一个包含客户配置文件的向量数据库,这些配置文件表示为高维向量,你想找到与给定参考客户相似的客户。

  1. 定义参考客户向量:首先,为参考客户定义一个向量表示。这可以通过提取相关特征或属性并将它们转换为向量格式来完成。
  2. 执行相似性搜索:使用合适的算法,如k-最近邻(k-NN)或余弦相似度,在向量数据库中执行相似性搜索。该算法将根据相似性分数识别参考客户向量的最近邻居。
  3. 检索相似客户:检索与上一步中识别的最近邻居向量对应的客户配置文件。这些配置文件将根据定义的相似性度量表示与参考客户相似的客户。
  4. 呈现结果:最后,将检索到的客户配置文件或相关信息呈现给用户,例如显示他们的名字、人口统计信息或购买历史。此信息可用于推荐、定向营销活动或个性化体验。

知识图谱的优势

相比于向量数据库,知识图谱提供了更精确和具体信息。向量数据库表示两个实体或概念之间的相似性或关联性,而知识图谱能够更好地理解它们之间的关系。例如,知识图谱可以告诉你“埃菲尔铁塔”是“巴黎”的地标,而向量数据库只能表示这两个概念的相似程度。这可以帮助LLM生成更准确和相关的文本。

知识图谱支持比向量数据库更多样化和复杂的查询。向量数据库主要基于向量距离、相似度或最近邻来回答问题,这些仅限于直接相似度测量。相比之下,知识图谱可以处理基于逻辑运算符(如“具有属性Z的所有实体是什么?”或“W和V的共同类别是什么?”)的查询。这可以帮助LLM生成更多样化和有趣的文本。

知识图谱比向量数据库能够进行更多的推理和推断。向量数据库只能提供直接存储在数据库中的信息。相比之下,知识图谱可以从实体或概念之间的关系推导出间接信息。例如,知识图谱可以根据“巴黎是法国的首都”和“法国位于欧洲”的事实推断出“埃菲尔铁塔位于欧洲”。这可以帮助LLM生成更符合逻辑和一致的文本。

LlamaIndex

LlamaIndex是一个编排框架,用于简化将私有数据与公共数据集成以构建使用大型语言模型(LLMs)的应用程序。它提供了数据摄取、索引和查询的工具,使其成为生成式AI需求的一种多功能解决方案。

嵌入模型

嵌入模型需要将文本转换为所提供文本的信息的数字表示形式。该表示形式捕获了所嵌入内容的语义含义,使其适用于许多行业应用。在这里,我们使用了“thenlper/gte-large”模型。

LLM

大型语言模型需要根据提供的问题和上下文生成响应。在这里,我们使用了Zephyr 7B beta模型。

代码实现

1、安装所有依赖库

pip install llama_index pyvis Ipython langchain pypdf

2、设置日志

  1. import logging
  2. import sys
  3. #
  4. logging.basicConfig(stream=sys.stdout, level=logging.INFO)
  5. logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))

3、导包

  1. from llama_index import (SimpleDirectoryReader,
  2. LLMPredictor,
  3. ServiceContext,
  4. KnowledgeGraphIndex)
  5. #
  6. from llama_index.graph_stores import SimpleGraphStore
  7. from llama_index.storage.storage_context import StorageContext
  8. from llama_index.llms import HuggingFaceInferenceAPI
  9. from langchain.embeddings import HuggingFaceInferenceAPIEmbeddings
  10. from llama_index.embeddings import LangchainEmbedding
  11. from pyvis.network import Network
SimpleDirectoryReader:用于读取非结构化数据。
LLMPredictor:用于使用大型语言模型(LLM)生成预测。
ServiceContext:提供协调各种服务所需的上下文数据。
KnowledgeGraphIndex:用于构建和操作知识图谱。
SimpleGraphStore:用作存储图数据的简单仓库。
HuggingFaceInferenceAPI:用于利用开源LLM的模块。

4、引入LLM

  1. HF_TOKEN = "Your Huggaingface api key "
  2. llm = HuggingFaceInferenceAPI(
  3. model_name="HuggingFaceH4/zephyr-7b-beta", token=HF_TOKEN
  4. )

5、引入embedding

  1. embed_model = LangchainEmbedding(
  2. HuggingFaceInferenceAPIEmbeddings(api_key=HF_TOKEN,model_name="thenlper/gte-large")
  3. )

6、装载数据

  1. documents = SimpleDirectoryReader("/content/Documents").load_data()
  2. print(len(documents))

7、构建知识图谱索引

  1. #setup the service context
  2. service_context = ServiceContext.from_defaults(
  3. chunk_size=256,
  4. llm=llm,
  5. embed_model=embed_model
  6. )
  7. #setup the storage context
  8. graph_store = SimpleGraphStore()
  9. storage_context = StorageContext.from_defaults(graph_store=graph_store)
  10. #Construct the Knowlege Graph Undex
  11. index = KnowledgeGraphIndex.from_documents( documents=documents,
  12. max_triplets_per_chunk=3,
  13. service_context=service_context,
  14. storage_context=storage_context,
  15. include_embeddings=True)

8、从文档中创建知识图谱

  1. Text: page_label: 2
  2. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  3. What is an ESOP?
  4. Triplets:
  5. (page_label, is, 2)
  6. (ESOP, is, What is an ESOP?)
  7. ---------------------
  8. Text: page_label: 3
  9. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  10. Why Offer an ESOP?
  11. Triplets:
  12. (page_label, is, 3)
  13. (ESOP, is, Why Offer an ESOP?)
  14. ---------------------
  15. Text: page_label: 4
  16. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-P
  17. (page_label, is, part of)
  18. (page_label, is, Table of Contents)
  19. (file_path, is, path of)
  20. (file_path, is, /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf)
  21. (ESOP, is, part of)
  22. (ESOP, is, Intro to Options Plans)
  23. (Option, is, part of)
  24. (Option, is, Intro to Options Plans)
  25. (Lifecycle of a Startup ESOP, is, part of)
  26. (Lifecycle of a Startup ESOP, is, Intro to Options Plans)
  27. (Common Terms in an Options Package, is, part of)
  28. (Common Terms in an Options Package, is, Intro to Options Plans)
  29. (Why Issue Options to Employees, is, part of)
  30. (Why Issue Options to Employees, is, Intro to Options Plans)
  31. (A Defining Characteristic of Startup Culture, is, part of)
  32. (A Defining Characteristic of Startup Culture, is, Why Issue Options to Em
  33. (ESOP, is, equity compensation plan)
  34. (ESOP, is, employee stock option plan)
  35. (ESOP, is, part of startup culture)
  36. (ESOP, is, necessary part of capital structure)
  37. (ESOP, is, defined characteristic of startup culture)
  38. (ESOP, is, defined characteristic of startup culture)
  39. (ESOP, is, defined characteristic of startup culture)
  40. (ESOP, is, defined characteristic of startup culture)
  41. (ESOP, is, defined characteristic of startup culture)
  42. (ESOP, is, defined characteristic of startup culture)
  43. (ESOP, is, defined characteristic of startup culture)
  44. (ESOP, is, defined characteristic of startup culture)
  45. (ESOP, is, defined characteristic of startup culture)
  46. (ESOP, is, defined characteristic of startup culture)
  47. (ESOP, is, defined characteristic of startup culture)
  48. (ESOP, is, defined characteristic of startup culture)
  49. (ESOP, is, defined characteristic of startup culture)
  50. (ESOP, is, defined characteristic of startup culture)
  51. (ESOP, is, defined characteristic of startup culture)
  52. (ESOP, is, defined characteristic of startup culture)
  53. (page_label, is, 3)
  54. (INTRO TO OPTIONS PLANS, is, Part I)
  55. ---------------------
  56. Text: The 2018 Annual Report of the Board of Trustees of the University of Arkansas System is presented here as a PDF file.
  57. Triplets:
  58. (The, is, PDF file)
  59. (The, is presented, here)
  60. (The, is, The 2018 Annual Report of the Board of Trustees of the University of Arkansas System)
  61. ---------------------
  62. Text: The 2018 Annual Report of the Board of Trustees of the University of Arkansas System is presented here as a PDF file.
  63. Triplets:
  64. (The, is, PDF file)
  65. (The, is presented, here)
  66. (The, is, The 2018 Annual Report of the Board of Trustees of the University of Arkansas System)
  67. ---------------------
  68. Text: The 2018 Annual Report of the Board of Trustees of the University of Arkansas System is presented here as a PDF file.
  69. Triplets:
  70. (The, is, PDF file)
  71. (The, is presented, here)
  72. (The,
  73. (ESOP, is, Employee Stock Options Plan)
  74. (ESOP, is, allocation)
  75. (ESOP, is, plan)
  76. ---------------------
  77. Text: page_label: 5
  78. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  79. What is an ESOP?
  80. •An Employee Stock Options Plan (ESOP)
  81. •An allocation of shares that will be granted to employees in the future
  82. in the form of stock options
  83. –How much equity should we set aside for employees?
  84. •A plan for how these options will be distributed:
  85. –How many shares will individual employees receive?
  86. –What terms will govern these grants?
  87. •The plan is as important as the allocation!
  88. Triplets:
  89. (ESOP, is, allocation)
  90. (ESOP, is, plan)
  91. (ESOP, is, important)
  92. ---------------------
  93. Text: page_label: 6
  94. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-
  95. (Option, is, effective form of equity ownership)
  96. (Option, has, intrinsic value)
  97. (Option, is, locked-in price for shares)
  98. ---------------------
  99. Text: page_label: 1
  100. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  101. What is an ESOP?
  102. •What is an ESOP?
  103. –A qualified retirement plan
  104. –A tax-qualified defined contribution plan
  105. –A plan that is primarily designed to
  106. provide retirement benefits to employees
  107. –A plan that is primarily designed to
  108. provide benefits in the form of stock
  109. –A plan that is primarily designed to
  110. provide benefits in the form of stock
  111. –A plan that is primarily designed to
  112. provide benefits in the form of stock
  113. –A plan that is primarily designed to
  114. provide benefits in the form of stock
  115. –A plan that is primarily designed to
  116. provide benefits in the form of stock
  117. –A plan that is primarily designed to
  118. provide benefits in the form of stock
  119. (Option, is, right to purchase)
  120. (Option, is, set price)
  121. (Option, is, certain period of time)
  122. ---------------------
  123. Text: page_label: 1
  124. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  125. What is an ESOP?
  126. •What is an ESOP?
  127. –A qualified retirement plan
  128. –A tax-qualified plan that meets
  129. ERISA requirements
  130. –A plan that is primarily designed
  131. to provide retirement benefits to
  132. employees
  133. –A plan that is primarily designed
  134. to provide benefits in the form
  135. of employer securities
  136. –A plan that is primarily designed
  137. to provide benefits in the form
  138. of employer securities that are
  139. acquired through purchase,
  140. receipt from a corporate parent,
  141. or through the accumulation of
  142. distributions on employer securities
  143. –A plan that is primarily designed
  144. to provide benefits in the form
  145. of employer securities that are
  146. acquired through the accumulation
  147. of
  148. (Lifecycle of a Startup ESOP, involves, founders and early investors)
  149. (Lifecycle of a Startup ESOP, involves, management and the Board of Directors)
  150. (Lifecycle of a Startup ESOP, involves, employees)
  151. (Employees, receive, options packages)
  152. (Options, are, exercised)
  153. (Options, are, granted)
  154. (Options, are, issued)
  155. (Options, are, marketable)
  156. (Options, are, forfeitable)
  157. (Options, are, vested)
  158. (Shares, are, acquired)
  159. (Shares, are, granted)
  160. (Shares, are, marketable)
  161. (Shares, are, owned)
  162. (Shares, are, vested)
  163. (Strike price, is, paid)
  164. (Strike price, is, set)
  165. (Strike price, is, specified)
  166. ---------------------
  167. Text: page_label: 11
  168. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  169. Lifecycle of a Startup ESOP
  170. •Found
  171. (Common Terms in an Options Package, is, Number of Shares)
  172. (Common Terms in an Options Package, is, Strike Price)
  173. (Common Terms in an Options Package, is, Vesting Schedule)
  174. (Common Terms in an Options Package, is, Cliff Period)
  175. (Common Terms in an Options Package, is, Expiration Date)
  176. ---------------------
  177. Text: page_label: 1
  178. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  179. Executive Summary
  180. This document outlines the best practices for designing and implementing an employee stock option plan (ESOP) for a private company. The document is intended to provide a framework for designing an ESOP that is tailored to the specific needs of the company and its employees. The document is not intended to be a comprehensive guide to ESOP design, but rather a high-level overview of the key considerations that should be taken into account when designing an ESOP.
  181. Triplets:
  182. (Executive Summary, is, High-level overview)
  183. (Executive Summary, is, Key considerations)
  184. (Executive Summary
  185. (Why Issue Options to Employees?, attracts, top recruits)
  186. (Why Issue Options to Employees?, retains, employees)
  187. (Why Issue Options to Employees?, aligns, incentives)
  188. (Why Issue Options to Employees?, rewards, value creation)
  189. (Why Issue Options to Employees?, encourages, long -term thinking)
  190. ---------------------
  191. Text: page_label: 10
  192. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  193. How Should Options Be Granted?
  194. At the Right Time: options should be granted at the right time in the
  195. company’s life cycle, when the company has achieved a certain level
  196. of success and the value of the company is clear
  197. At the Right Price: options should be granted at a fair price, based on
  198. the company’s valuation at the time of grant
  199. At the Right Size: options should be granted in the right size, based
  200. on the employee’s role and contribution to the company
  201. Triplets:
  202. (
  203. (Startups, are, unique case)
  204. (Startups, use, options)
  205. (Startups, seeking to achieve, big exit)
  206. ---------------------
  207. Text: page_label: 10
  208. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  209. The defining difference between Silicon Valley companies and almost
  210. every other industry in the U.S. Is the virtually universal practice among
  211. tech companies of distributing meaningful equity (usually in the form of
  212. stock options) to ordinary employees . A Defining Characteristic of Startup Culture
  213. Steven Johnson, Technology Writer
  214. •Startups are a unique case . Unlike at larger corporations, employee
  215. ownership is an essential element of startup communities and culture
  216. As high -risk/high -reward enterprises, startups use options to align
  217. employee compensation with the risk -prone mentality of the
  218. business
  219. –Startups seeking to achieve a “big exituse options to align all
  220. employees to drive toward this desired outcome
  221. Triplets:
  222. (Startups
  223. (ESOP, is, necessary part of, capital structure)
  224. (VCs, require, ESOPs)
  225. (Startups, are compelled, to offer, options packages)
  226. ---------------------
  227. Text: page_label: 11
  228. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  229. The ESOP as a Recruitment and Retention Tool
  230. •ESOPs are a critical tool for recruiting and retaining employees
  231. In a competitive job market, ESOPs can be used to attract top talent
  232. In a tight labor market, ESOPs can be used to retain key employees
  233. In a volatile market, ESOPs can be used to retain employees during
  234. a downturn
  235. In a high-growth company, ESOPs can be used to retain employees during
  236. a period of rapid expansion
  237. In a company with a high employee turnover rate, ESOPs can be used to
  238. reduce turnover and associated costs
  239. In a company with a high executive turnover rate, ESOPs can be used to
  240. (page_label: 11, is, stage)
  241. (stage, is, pre-seed)
  242. (stage, is, seed)
  243. (stage, is, early -vc)
  244. ---------------------
  245. Text: page_label: 11
  246. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  247. page_label: 12
  248. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  249. page_label: 13
  250. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  251. page_label: 14
  252. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  253. page_label: 15
  254. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices
  255. (ESOP, is necessary for, Pre-seed)
  256. (ESOP, is not necessary for, Pre-seed)
  257. (ESOP, can be helpful for, Pre-seed)
  258. (ESOP, is not necessary for, Seed)
  259. (ESOP, is required for, Early -VC)
  260. (ESOP, must be created for, Early -VC)
  261. (ESOP, serves as a guideline for, Early -VC)
  262. (ESOP, is important to have standardized for, Late-VC)
  263. (ESOP, is gone for, Growth)
  264. (ESOP, shares remaining are more valuable for, Growth)
  265. (ESOP, is used to allow new hires to share in the upside for, Growth)
  266. (ESOP, should be set up between, Pre-seed and, Early -VC)
  267. ---------------------
  268. Text: page_label: 12
  269. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  270. How Much Equity Should You Grant?
  271. Stage Considerations Takeaway
  272. Pre-seed Found
  273. (Communicating options to employees, can be communicated, % versus $)
  274. (Communicating options to employees, can be communicated, %)
  275. (Communicating options to employees, can be communicated, $)
  276. (Communicating options to employees, can be communicated, 0.5%)
  277. (Communicating options to employees, can be communicated, $200,000)
  278. ---------------------
  279. Text: page_label: 13
  280. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  281. Exercise Price: Market Price vs. Discount
  282. When setting the exercise price for options, there are two
  283. approaches: (1) set the price equal to the market price of
  284. the stock at the time of grant, or (2) set the price at a
  285. discount to the market price.
  286. Market Price:
  287. •Fair to employees and the company
  288. No tax deduction for company
  289. •Employees can sell immediately
  290. •Employees can exercise immediately
  291. Discount:
  292. (Communication of options packages, recommended, dollar value)
  293. (Communication of options packages, recommended against, percent of the company)
  294. (Communication of options packages, effective when, dollar value)
  295. ---------------------
  296. Text: page_label: 13
  297. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  298. or (2) a dollar value based on the
  299. current valuation; we encourage the latter when possible
  300. % $
  301. “We are granting you options equivalent to
  302. 0.5% of the company’s equity”
  303. Considerations:
  304. At an early stage, the only way
  305. to communicate options grants given no true
  306. valuation of the company
  307. •Hard for employees to grasp what they
  308. are really getting (“0.5% seems too little”)
  309. •Invites a negotiation about what percent
  310. of the company an employee really
  311. deserves “We are granting you options equivalent to
  312. $200,000 of company stock”
  313. Considerations
  314. (page_label, is, 12)
  315. (file_path, is, /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf)
  316. (5%, is, equivalent to)
  317. (5%, is, $200,000 of company stock)
  318. (Considerations, is, highly effective way to communicate the true value of an options grant)
  319. ---------------------
  320. Text: The 2018 FIFA World Cup was the 21st FIFA World Cup, an international men's football tournament contested by the national teams of FIFA member associations. It took place in Russia from 14 June to 15 July 2018. It was the first World Cup to be held in Eastern Europe, and the 11th time that it had been held in Europe. At an estimated cost of over $14.2 billion, it is the most expensive World Cup.
  321. Triplets:
  322. (2018 FIFA World Cup, is, 21st FIFA World Cup)
  323. (2018 FIFA World Cup, took place in, Russia)
  324. (201
  325. (HOW MUCH TO GRANT, Part II, )
  326. ---------------------
  327. Text: page_label: 13
  328. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  329. HOW MUCH TO GRANT Part II
  330. Triplets:
  331. (HOW MUCH TO GRANT, Part II, )
  332. ---------------------
  333. Text: page_label: 13
  334. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  335. HOW MUCH TO GRANT Part II
  336. Triplets:
  337. (HOW MUCH TO GRANT, Part II, )
  338. ---------------------
  339. Text: page_label: 13
  340. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  341. HOW MUCH TO GRANT Part II
  342. Triplets:
  343. (HOW MUCH TO GRANT, Part II, )
  344. ----------------
  345. (Two Approaches, is, reality)
  346. (Creating an ESOP, requires, a combination of top-down and bottom -up planning)
  347. (Decide the total amount of equity to be granted, is, part of creating an ESOP)
  348. (Allocate these shares to employees over time, is, part of creating an ESOP)
  349. (Decide the appropriate size of individual equity grants by position, is, part of creating an ESOP)
  350. (Issue these shares as employees are hired, is, part of creating an ESOP)
  351. ---------------------
  352. Text: page_label: 15
  353. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  354. Two Approaches
  355. In reality, creating an ESOP will require a combination of
  356. top-down and bottom -up planning Top Down Bottom Up
  357. Decide the total amount of
  358. equity to be granted; allocate
  359. these shares to employees
  360. over time Decide the appropriate size of
  361. individual equity grants by
  362. position; issue these shares as
  363. employees are
  364. (Top -Down Process, consists of, determining)
  365. (Top -Down Process, consists of, creating)
  366. (Top -Down Process, consists of, scheduling)
  367. Text: page_label: 16
  368. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  369. The Bottom -Up Process
  370. 1.Determine the number of shares to be granted to each employee
  371. 2.Determine the grant date
  372. 3.Determine the vesting schedule
  373. Triplets:
  374. (Bottom -Up Process, consists of, determining)
  375. (Bottom -Up Process, consists of, determining)
  376. (Bottom -Up Process, consists of, determining)
  377. Text: page_label: 17
  378. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  379. The Bottom -Up Process (continued)
  380. 1.Determine the exercise price
  381. 2.Determine the expiration date
  382. Triplets:
  383. (Bottom -Up Process, consists
  384. (page_label, is, 16)
  385. (page_label, represents, how much equity to set aside in the esop)
  386. (page_label, has, values of 15-20% for generally non-founder employees)
  387. ---------------------
  388. Text: The 2018-19 budget for the Department of Energy (DOE) includes $3.7 billion for the Office of Science (SC), an increase of $645 million (21.1%) over the 2018 enacted level.
  389. Triplets:
  390. (The, 2018-19 budget for the Department of Energy, includes, $3.7 billion for the Office of Science)
  391. (The, 2018-19 budget for the Department of Energy, is, an increase of $645 million over the 2018 enacted level)
  392. (The, 2018-19 budget for the Department of Energy, represents, a 21.1% increase over the 2018 enacted level for the Office of Science)
  393. ---------------------
  394. Text: The 2018
  395. (page_label, is, 16)
  396. (file_path, is, /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf)
  397. (no, is, 0)
  398. (technology emphasis, is, 0)
  399. (geographic focus, is, region that is not considered a startup hub)
  400. (hiring needs, are primarily, administrative or back -office team members)
  401. (percentage of company issued to non founder employees, is between, 15% and 20%)
  402. (founders, are, top managers, but hire others to fill key technical or functional roles)
  403. (dna of the company, is, applying technology to a non -technical industry)
  404. (geographic focus, is, either wholly or partially in a startup hub)
  405. (hiring needs, are primarily, sales and marketing team members)
  406. (founders, are not top managers in the business, or plan to step aside)
  407. (dna of the company, is, technology, engineering, or data science)
  408. (geographic focus, is, in a leading startup hub such as sf,
  409. (page_label, is, 16)
  410. (file_path, is, /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf)
  411. (companies, issue, up to 25%)
  412. (founders, are, top managers)
  413. (founders, are not, top managers in the business, or)
  414. (DNA, is, in applying technology to a non -technical industry)
  415. (DNA, is, in technology, engineering, or data science)
  416. (geographic focus, is, wholly or partially in a startup hub)
  417. (geographic focus, is, in a leading startup hub such as SF, NYC or Boston)
  418. (hiring needs, are, primarily sales and marketing team members)
  419. (hiring needs, are, primarily engineering, development, or technical team members)
  420. ---------------------
  421. Text: The 2018-19 season of the National Basketball Association (NBA) is the 72nd season of the National Basketball Association.
  422. Triplets:
  423. (2018-19 season, is, the 7
  424. (Typical Distribution Schedule, consists of, Seniority)
  425. (Typical Distribution Schedule, consists of, Equity Allocation)
  426. (First, consists of, 10%)
  427. (Next, consists of, 5%)
  428. (Next, consists of, 5%)
  429. (CTO, consists of, 1-5%)
  430. (Key Developer or Engineer, consists of, 1-2%)
  431. (Other Functional Team Member, consists of, 0.5-1.5%)
  432. (No non -founding member of the senior team, should not exceed, 10%)
  433. ---------------------
  434. Text: page_label: 18
  435. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  436. 3. Vesting Schedule
  437. •Four year vesting schedule is most common.
  438. •Cliff vesting is less common, but can be used to retain key employees.
  439. •Monthly vesting is less common, but can be used to align employee interests with company performance.
  440. Triplets:
  441. (Vesting Schedule, is most common
  442. (Bottom -Up Process, consists of, Segment your human resources)
  443. (Bottom -Up Process, consists of, Create pay multipliers for each job function)
  444. (Bottom -Up Process, consists of, Determine the dollar value of an options grant)
  445. (Bottom -Up Process, consists of, Determine the current share price)
  446. (Bottom -Up Process, consists of, Calculate options grants)
  447. ---------------------
  448. Text: page_label: 19
  449. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  450. The Top-Down Process
  451. 1.Determine the total dollar amount to be spent on options
  452. 2.Determine the number of shares to be reserved for options
  453. 3.Determine the number of options to be granted
  454. 4.Determine the exercise price
  455. 5.Determine the vesting schedule
  456. Triplets:
  457. (Top-Down Process, consists of, Determine the total dollar amount to be spent on options)
  458. (Top-Down Process, consists of, Determine the number of shares to be reserved for options)
  459. (Top-
  460. (Segment Your Human Resources, is, segmentation)
  461. (Segment Your Human Resources, has, Segment Roles)
  462. (Segment Your Human Resources, has, Award)
  463. ---------------------
  464. Text: page_label: 20
  465. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  466. 2. Communicate Early and Often
  467. •Communicate the plan to all employees as soon as possible
  468. •Communicate the plan to all new hires as part of their orientation
  469. •Communicate the plan to all employees at least annually
  470. •Communicate the plan to all employees when there is a material change
  471. Triplets:
  472. (Communicate Early and Often, is, communication)
  473. (Communicate Early and Often, has, Communicate the plan to all employees as soon as possible)
  474. (Communicate Early and Often, has, Communicate the plan to all new hires as part of their orientation)
  475. (Communicate Early and Often, has, Communicate the plan to all employees at least annually)
  476. (Communicate Early and Often,
  477. (2, establish, Pay Multipliers for Each Role)
  478. (Segment, Roles, 2)
  479. (Segment, Award, ?)
  480. ---------------------
  481. Text: page_label: 21
  482. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  483. 3. Establish Vesting Schedules
  484. Segment Vesting Schedule
  485. in Years or %?
  486. Triplets:
  487. (3, establish, Vesting Schedules)
  488. (Segment, Vesting Schedule, ?)
  489. ---------------------
  490. Text: page_label: 22
  491. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  492. 4. Establish Performance Criteria
  493. Segment Performance Criteria
  494. in % or $?
  495. Triplets:
  496. (4, establish, Performance Criteria)
  497. (Segment, Performance Criteria, ?)
  498. ---------------------
  499. Text: page_label: 23
  500. file_path: /content/Documents/Employee-Stock-Option-
  501. (page_label, is, 20)
  502. (2, establish, Pay Multipliers for Each Role)
  503. (Segment, is, Roles)
  504. (Segment, is, Award)
  505. (Segment, is, Options Multiplier)
  506. (Segment, is, Founders)
  507. (Segment, is, Co-Founders)
  508. (Segment, is, %)
  509. (Segment, is, Founding Team)
  510. (Segment, is, Technical & Product)
  511. (Segment, is, Early -Stage Hires)
  512. (Segment, is, Senior Team)
  513. (Segment, is, C-Level)
  514. (Segment, is, Directors / VPs)
  515. (Segment, is, Functional / Technical Team)
  516. (Segment, is, Support Team)
  517. (Segment, is, $)
  518. (Segment, is, 0.5x)
  519. (Segment, is, 1.0x)
  520. (Segment, is, 0.25x)
  521. (Segment, is, 0.5x)
  522. (Segment, is, 0.1x)
  523. (Segment, is, 0.0x)
  524. (page_label, is, 2)
  525. (Employee, Base Salary, x)
  526. (Employee, Options, x)
  527. (Employee, Options Multiplier, based on the employee’s role in HR segmentation schedule)
  528. ---------------------
  529. Text: page_label: 21
  530. file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
  531. 3. Determine the Dollar Value of the Options Grant
  532. Employee
  533. Base Salary = x Options
  534. Multiplier Dollar Value
  535. of Options Grant Base Salary as negotiated with
  536. the employee at the time of hire
  537. or promotion
  538. Options Multiplier is decided
  539. based on the employee’s role in
  540. the HR segmentation schedule
  541. Triplets:
  542. (Employee, Base Salary, x)
  543. (Employee, Options, x)
  544. (Employee, Options Multiplier, based on the employee’s role in HR segmentation schedule)
  545. ---------------------
  546. Text: page_label: 21
  547. file_path: /content/Documents/Employ

9、构建查询引擎来查询知识图谱

  1. query = "What is ESOP?"
  2. query_engine = index.as_query_engine(include_text=True,
  3. response_mode ="tree_summarize",
  4. embedding_mode="hybrid",
  5. similarity_top_k=5,)
  6. #
  7. message_template =f"""<|system|>Please check if the following pieces of context has any mention of the keywords provided in the Question.If not then don't know the answer, just say that you don't know.Stop there.Please donot try to make up an answer.</s>
  8. <|user|>
  9. Question: {query}
  10. Helpful Answer:
  11. </s>"""
  12. #
  13. response = query_engine.query(message_template)
  14. #
  15. print(response.response.split("<|assistant|>")[-1].strip())
  16. #####OUTPUT #####################
  17. ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that allows employees to receive company stock or stock options as part of their compensation. In simpler terms, it is a plan that allows employees to own a portion of the company they work for. This can be a motivating factor for employees as they have a direct stake in the company's success. ESOPs can also be a tax-efficient way for companies to provide retirement benefits to their employees.
  18. query ="Who is Atul?"
  19. message_template =f"""<|system|>Please check if the following pieces of context has any mention of the keywords provided in the Question.If not then don't know the answer, just say that you don't know.Stop there.Please donot try to make up an answer.</s>
  20. <|user|>
  21. Question: {query}
  22. Helpful Answer:
  23. </s>"""
  24. #
  25. response = query_engine.query(message_template)
  26. #
  27. print(response.response.split("<|assistant|>")[-1].strip())
  28. ################OUTPUT#####################
  29. I do not have prior knowledge or context about who atul is. Please provide more information or context so I can assist you better. Without any further context, I do not know the answer to your question.

10、可视化表示

  1. from pyvis.network import Network
  2. from IPython.display import display
  3. g = index.get_networkx_graph()
  4. net = Network(notebook=True,cdn_resources="in_line",directed=True)
  5. net.from_nx(g)
  6. net.show("graph.html")
  7. net.save_graph("Knowledge_graph.html")
  8. #
  9. import IPython
  10. IPython.display.HTML(filename="/content/Knowledge_graph.html")

11、持久化保存

storage_context.persist()

总结

对于语言模型(LLM)幻觉,知识图谱被证明优于向量数据库。知识图谱提供更准确、多样化、有趣、逻辑和一致的信息,减少了LLM中出现幻觉的可能性。这种优越性源于它们能够提供关于实体之间关系的精确细节,而不仅仅是表示相似性,支持更复杂的查询和逻辑推理。

向量数据库以其数字数组在相似性搜索和最佳匹配场景中表现出色。最终,两者之间的选择取决于项目的需求,包括数据的性质、关系探索的需要以及预期的查询类型。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/269102
推荐阅读
相关标签
  

闽ICP备14008679号