使用知识图谱和Llama-Index实施RAG

2023年12月04日 由 alex 发表 1144 0

6


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


7


向量数据库是什么?


向量数据库是一个包含高维向量的集合,这些向量代表实体或概念,如单词、短语或文档。向量数据库可以用来衡量不同实体或概念之间的相似性或相关性,这些衡量基于它们的向量表示。


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


知识图谱是什么?


知识图谱是一个节点和边的集合,它们代表实体或概念以及它们之间的关系,如事实、属性或类别。


知识图谱可以用来查询或推断关于不同实体或概念的事实信息,这些信息基于它们的节点和边的属性。


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


查询一图数据库涉及遍历图结构并基于特定标准检索节点、关系或模式。这里有一个简单的例子,展示了如何查询一个图数据库:


假设你有一个表示社交网络的图数据库,用户是节点,他们的关系(例如,友谊)被表示为连接节点的边。你想为一个给定的用户找到朋友的朋友(共同联系人)。


1. 从参考用户开始:


在图数据库中识别代表参考用户的节点。这可以通过查询特定的用户标识符或其他相关标准来完成。


2. 遍历图:


使用图查询语言,如Cypher(用于Neo4j)或Gremlin,从参考用户节点遍历图。编写一个查询,指定你想要探索的模式或关系。在这个例子中,你想找到朋友的朋友。示例Cypher查询:


MATCH (:User {userId: ‘referenceUser’})-[:FRIEND]->()-[:FRIEND]->(fof:User)


RETURN fof


这个查询从参考用户开始,遵循FRIEND关系到另一个节点(朋友),然后遵循另一个FRIEND关系来找到朋友的朋友(fof)。


3. 检索结果:


针对图数据库执行查询,并根据查询模式检索结果节点(朋友的朋友)。如果需要,你可以获取有关检索到的节点的特定属性或附加信息。


4. 展示结果:


向用户展示检索到的朋友的朋友或根据需要进一步处理数据。这些信息可以用于建议、网络分析或其他相关目的。


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


而查询向量数据库通常涉及搜索相似的向量或基于特定标准检索向量。这里有一个简单的例子,展示了如何查询一个向量数据库:


假设你有一个包含以高维向量表示的客户档案的向量数据库,你想找到与给定参考客户相似的客户。


1. 定义参考客户向量:


首先为参考客户定义一个向量表示。这可以通过提取相关特征或属性并将它们转换为向量格式来完成。


2. 执行相似性搜索:


使用合适的算法,如k-最近邻(k-NN)或余弦相似性,对向量数据库进行相似性搜索。算法将基于相似性分数识别与参考客户向量最相近的邻居。


3. 检索相似的客户:


根据之前步骤识别的最近邻居向量,检索对应的客户档案。这些档案将代表与参考客户类似的客户,基于定义的相似性度量。


4. 展示结果:


最后,向用户展示检索到的客户档案或相关信息,例如显示他们的姓名、人口统计学或购买历史。这些信息可以用于推荐、针对性营销活动或个性化体验。


知识图谱的主要组成部分。


知识图谱通常由两个主要组件组成:


  1. 顶点/节点:代表知识领域中的实体或对象。每个节点对应一个唯一的实体,并由唯一的标识符标识。
  2. 边:代表两个节点之间的关系。


知识图谱中的三元组


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


  1. 主体:三元组所述的节点。
  2. 对象:关系指向的节点。
  3. 谓词:主体和客体之间的关系。


在以下的三元组示例中,“金奈国王”是主体,“在比赛中”是谓词,“大联盟板球”是宾语。


知识图谱比向量数据库在LLM幻觉中更好吗?


  • 知识图谱比向量数据库提供更精确和具体的信息。向量数据库指出两个实体或概念之间的相似性或相关性,而知识图谱可以更好地理解它们之间的关系。
  • 知识图谱支持比向量数据库更多样和复杂的查询。向量数据库主要可以回答基于向量距离、相似性或最近邻居的查询,这些都是基于直接相似性度量的查询。相比之下,知识图谱可以处理基于逻辑运算符的查询。
  • 知识图谱比向量数据库支持更多的推理和推断。向量数据库只能提供数据库中存储的直接信息。相比之下,知识图谱可以提供从实体或概念之间的关系推导出的间接信息。


总之,知识图谱比向量数据库更适合解决LLM中的幻觉问题。知识图谱为LLM提供更准确、相关、多样、有趣、逻辑和一致的信息。因此,使用知识图谱可以减少LLM中的幻觉现象,使它们在生成准确和事实文本时更可靠。但这里的关键是文档需要明确展示关系,否则知识图谱将无法捕捉到它。


向量数据库和知识图谱采用两种不同的方法来存储和表示数据。


向量数据库的方法是使用数值向量来表示数据,并主要用于相似性搜索。


  • 每个实体都表示为一个高维向量,实体之间的相似性基于向量距离计算。
  • *向量数据库非常适合基于相似性的操作,但可能在表示实体之间的复杂关系和语义含义方面存在困难。


相比之下,知识图谱旨在捕捉和表示对象之间的关系。


  • 知识图谱捕捉实体之间的复杂关系和依赖,并提供语义分析和推理能力。
  • 知识图谱可以回答基于逻辑运算符的复杂查询,并进行高级推理和知识发现。


图数据库主要关注对象之间的两两关系,而向量数据库关注向量的相似性。


此外,数据的存储方式也完全不同,


图数据库


  • 使用节点和边来表示关系的图数据库和
  • 图数据库非常适合分析实体之间的关系和复杂的网络。


向量数据库


  • 而向量数据库使用数值型数组。
  • 向量数据库非常适合相似性搜索和最佳匹配搜索。


选择使用哪种方法取决于数据性质及其关系、查询和分析要求以及在相似性搜索或关系探索方面的效率等多个重要因素。这两种方法都有自己的优势和劣势,具体的用例将决定哪种最适合。


主要比较因素:


  • 数据结构:数据存储完全不同,图是为了存储节点和边而构建的,非常适合绘制被视为第一类公民的关系。向量数据库将数据存储为数值型数组。
  • 数据检索和分析:图是为了分析实体之间的关系而构建的,而向量则擅长分析模式。
  • 查询:图查询实体之间的关系以及复杂的网络。向量数据库非常擅长相似性搜索或最佳匹配搜索。
  • 性能:根据查询焦点,基于关系处理查询的GraphDB / 知识图谱非常出色,而VectorDB提供快速的相似性搜索


总结来说,向量数据库和知识图谱使用不同的方法来存储和表示数据。向量数据库适合基于相似性的操作,而知识图谱旨在捕捉和分析复杂的关系和依赖。选择正确的方法取决于特定项目的具体要求和目标。


代码实现:


使用的技术栈:


  1. LlamaIndex:LlamaIndex是一个协调框架,简化了在构建使用大型语言模型(LLMs)的应用程序时,私有数据与公共数据集成。它提供了数据摄取、索引和查询的工具,是生成性AI需求的多功能解决方案。
  2. 嵌入模型:嵌入模型需要将文本转换为信息的数值表示形式,以提供的文本。表示捕获了正在嵌入的信息的语义含义,使其适用于许多行业应用。在这里,我们使用了“thenlper/gte-large”模型。
  3. LLM:大型语言模型根据提供的问题和上下文生成响应。在这里,我们使用了Zephyr 7B beta模型


逐步代码实现:


这个代码实现将向你展示如何使用Llama Index创建一个知识图谱。


  1. 我们将读取一个.pdf文件并将其转换为结构化的知识图谱。
  2. 将嵌入存储在一个图形数据存储库中。
  3. 检索与用户查询匹配的相关上下文
  4. 为llm提供响应以生成响应


实施步骤


安装所需的依赖项


%%capture
pip install llama_index pyvis Ipython langchain pypdf


启用诊断日志记录


  • 日志记录为代码执行提供宝贵的洞察。
  • 此处日志级别设定为“INFO”,它将输出有助于监控应用程序操作流程的消息。


import logging
import sys
#
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))


导入所需的依赖项


from llama_index import (SimpleDirectoryReader,
                         LLMPredictor,
                         ServiceContext,
                         KnowledgeGraphIndex)
#
from llama_index.graph_stores import SimpleGraphStore
from llama_index.storage.storage_context import StorageContext
from llama_index.llms import HuggingFaceInferenceAPI
from langchain.embeddings import HuggingFaceInferenceAPIEmbeddings
from llama_index.embeddings import LangchainEmbedding
from pyvis.network import Network


这里是对所提到的软件包的简洁概述


  • SimpleDirectoryReader:用于读取非结构化数据。
  • LLMPredictor:用于利用大型语言模型(LLM)生成预测。
  • ServiceContext:提供用于协调各种服务的关键上下文数据。
  • KnowledgeGraphIndex:构建和操控知识图谱所必需的。
  • SimpleGraphStore:作为存储图数据的简单存储库。
  • HuggingFaceInferenceAPI:用于利用开源LLM的模块。


设置LLM


在这里,我们使用了Huggingface推理api端点。


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


设置嵌入模型


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


加载数据


documents = SimpleDirectoryReader("/content/Documents").load_data()"/content/Documents").load_data()
print(len(documents))
####Output###
44


构建知识图谱索引


创建一个知识图谱通常涉及专业复杂的任务。然而,通过使用Llama Index(LLM)、KnowledgeGraphIndex和GraphStore,我们可以从Llama Hub支持的任何数据源中便捷地创建一个相对有效的知识图谱。


#setup the service context
service_context = ServiceContext.from_defaults(
    chunk_size=256,
    llm=llm,
    embed_model=embed_model
)
#setup the storage context
graph_store = SimpleGraphStore()
storage_context = StorageContext.from_defaults(graph_store=graph_store)
#Construct the Knowlege Graph Undex
index = KnowledgeGraphIndex.from_documents( documents=documents,
                                           max_triplets_per_chunk=3,
                                           service_context=service_context,
                                           storage_context=storage_context,
                                          include_embeddings=True)


  • max_triplets_per_chunk:它控制每个数据块处理的关系三元组数量。
  • include_embeddings:切换是否在索引中包含向量嵌入以进行高级分析。


根据文档中创建知识图谱


Text: page_label: 22
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
What is an ESOP?
Triplets:
(page_label, is, 2)
(ESOP, is, What is an ESOP?)
---------------------
Text: page_label: 3
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
Why Offer an ESOP?
Triplets:
(page_label, is, 3)
(ESOP, is, Why Offer an ESOP?)
---------------------
Text: page_label: 4
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-P
(page_label, is, part of)
(page_label, is, Table of Contents)
(file_path, is, path of)
(file_path, is, /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf)
(ESOP, is, part of)
(ESOP, is, Intro to Options Plans)
(Option, is, part of)
(Option, is, Intro to Options Plans)
(Lifecycle of a Startup ESOP, is, part of)
(Lifecycle of a Startup ESOP, is, Intro to Options Plans)
(Common Terms in an Options Package, is, part of)
(Common Terms in an Options Package, is, Intro to Options Plans)
(Why Issue Options to Employees, is, part of)
(Why Issue Options to Employees, is, Intro to Options Plans)
(A Defining Characteristic of Startup Culture, is, part of)
(A Defining Characteristic of Startup Culture, is, Why Issue Options to Em
(ESOP, is, equity compensation plan)
(ESOP, is, employee stock option plan)
(ESOP, is, part of startup culture)
(ESOP, is, necessary part of capital structure)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(ESOP, is, defined characteristic of startup culture)
(page_label, is, 3)
(INTRO TO OPTIONS PLANS, is, Part I)
---------------------
Text: The 2018 Annual Report of the Board of Trustees of the University of Arkansas System is presented here as a PDF file.
Triplets:
(The, is, PDF file)
(The, is presented, here)
(The, is, The 2018 Annual Report of the Board of Trustees of the University of Arkansas System)
---------------------
Text: The 2018 Annual Report of the Board of Trustees of the University of Arkansas System is presented here as a PDF file.
Triplets:
(The, is, PDF file)
(The, is presented, here)
(The, is, The 2018 Annual Report of the Board of Trustees of the University of Arkansas System)
---------------------
Text: The 2018 Annual Report of the Board of Trustees of the University of Arkansas System is presented here as a PDF file.
Triplets:
(The, is, PDF file)
(The, is presented, here)
(The,
(ESOP, is, Employee Stock Options Plan)
(ESOP, is, allocation)
(ESOP, is, plan)
---------------------
Text: page_label: 5
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
What is an ESOP?  
•An Employee Stock Options Plan (ESOP)  
•An allocation  of shares that will be granted to employees in the future
in the form of stock options  
–How much equity should we set aside for employees?  
•A plan for how these options will be distributed:  
–How many shares will individual employees receive?  
–What terms will govern these grants?  
•The plan is as important as the allocation!
Triplets:
(ESOP, is, allocation)
(ESOP, is, plan)
(ESOP, is, important)
---------------------
Text: page_label: 6
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-
(Option, is, effective form of equity ownership)
(Option, has, intrinsic value)
(Option, is, locked-in price for shares)
---------------------
Text: page_label: 1
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
What is an ESOP?  
•What is an ESOP?  
–A qualified retirement plan  
–A tax-qualified defined contribution plan  
–A plan that is primarily designed to
provide retirement benefits to employees  
–A plan that is primarily designed to
provide benefits in the form of stock  
–A plan that is primarily designed to
provide benefits in the form of stock  
–A plan that is primarily designed to
provide benefits in the form of stock  
–A plan that is primarily designed to
provide benefits in the form of stock  
–A plan that is primarily designed to
provide benefits in the form of stock  
–A plan that is primarily designed to
provide benefits in the form of stock  

(Option, is, right to purchase)
(Option, is, set price)
(Option, is, certain period of time)
---------------------
Text: page_label: 1
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
What is an ESOP?  
•What is an ESOP?  
–A qualified retirement plan  
–A tax-qualified plan that meets
ERISA requirements  
–A plan that is primarily designed
to provide retirement benefits to
employees  
–A plan that is primarily designed
to provide benefits in the form
of employer securities  
–A plan that is primarily designed
to provide benefits in the form
of employer securities that are
acquired through purchase,
receipt from a corporate parent,
or through the accumulation of
distributions on employer securities  
–A plan that is primarily designed
to provide benefits in the form
of employer securities that are
acquired through the accumulation
of
(Lifecycle of a Startup ESOP, involves, founders and early investors)
(Lifecycle of a Startup ESOP, involves, management and the Board of Directors)
(Lifecycle of a Startup ESOP, involves, employees)
(Employees, receive, options packages)
(Options, are, exercised)
(Options, are, granted)
(Options, are, issued)
(Options, are, marketable)
(Options, are, forfeitable)
(Options, are, vested)
(Shares, are, acquired)
(Shares, are, granted)
(Shares, are, marketable)
(Shares, are, owned)
(Shares, are, vested)
(Strike price, is, paid)
(Strike price, is, set)
(Strike price, is, specified)
---------------------
Text: page_label: 11
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
Lifecycle of a Startup ESOP  
•Found
(Common Terms in an Options Package, is, Number of Shares)
(Common Terms in an Options Package, is, Strike Price)
(Common Terms in an Options Package, is, Vesting Schedule)
(Common Terms in an Options Package, is, Cliff Period)
(Common Terms in an Options Package, is, Expiration Date)
---------------------
Text: page_label: 1
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
Executive Summary  
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.
Triplets:
(Executive Summary, is, High-level overview)
(Executive Summary, is, Key considerations)
(Executive Summary
(Why Issue Options to Employees?, attracts, top recruits)
(Why Issue Options to Employees?, retains, employees)
(Why Issue Options to Employees?, aligns, incentives)
(Why Issue Options to Employees?, rewards, value creation)
(Why Issue Options to Employees?, encourages, long -term thinking)
---------------------
Text: page_label: 10
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
How Should Options Be Granted?  
•At the Right Time:  options should be granted at the right time in the
company’s life cycle, when the company has achieved a certain level
of success and the value of the company is clear  
•At the Right Price:  options should be granted at a fair price, based on
the company’s valuation at the time of grant  
•At the Right Size:  options should be granted in the right size, based
on the employee’s role and contribution to the company  
Triplets:
(
(Startups, are, unique case)
(Startups, use, options)
(Startups, seeking to achieve, big exit)
---------------------
Text: page_label: 10
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
The defining difference between Silicon Valley companies and almost
every other industry in the U.S. Is the virtually universal practice among
tech companies of distributing meaningful equity (usually in the form of
stock options) to ordinary employees .  A Defining Characteristic of Startup Culture  
Steven Johnson, Technology Writer  
•Startups are a unique case . Unlike at larger corporations, employee
ownership is an essential element of startup communities and culture  
–As high -risk/high -reward enterprises, startups use options to align
employee compensation with the risk -prone mentality of the
business  
–Startups seeking to achieve a “big exit” use options to align all
employees to drive toward this desired outcome
Triplets:
(Startups
(ESOP, is, necessary part of, capital structure)
(VCs, require, ESOPs)
(Startups, are compelled, to offer, options packages)
---------------------
Text: page_label: 11
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
The ESOP as a Recruitment and Retention Tool  
•ESOPs are a critical tool for recruiting and retaining employees
–In a competitive job market, ESOPs can be used to attract top talent
–In a tight labor market, ESOPs can be used to retain key employees
–In a volatile market, ESOPs can be used to retain employees during
a downturn  
–In a high-growth company, ESOPs can be used to retain employees during
a period of rapid expansion  
–In a company with a high employee turnover rate, ESOPs can be used to
reduce turnover and associated costs  
–In a company with a high executive turnover rate, ESOPs can be used to
(page_label: 11, is, stage)
(stage, is, pre-seed)
(stage, is, seed)
(stage, is, early -vc)
---------------------
Text: page_label: 11
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
page_label: 12
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
page_label: 13
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
page_label: 14
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
page_label: 15
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices
(ESOP, is necessary for, Pre-seed)
(ESOP, is not necessary for, Pre-seed)
(ESOP, can be helpful for, Pre-seed)
(ESOP, is not necessary for, Seed)
(ESOP, is required for, Early -VC)
(ESOP, must be created for, Early -VC)
(ESOP, serves as a guideline for, Early -VC)
(ESOP, is important to have standardized for, Late-VC)
(ESOP, is gone for, Growth)
(ESOP, shares remaining are more valuable for, Growth)
(ESOP, is used to allow new hires to share in the upside for, Growth)
(ESOP, should be set up between, Pre-seed and, Early -VC)
---------------------
Text: page_label: 12
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
How Much Equity Should You Grant?  
Stage  Considerations  Takeaway  
Pre-seed  Found
(Communicating options to employees, can be communicated, % versus $)
(Communicating options to employees, can be communicated, %)
(Communicating options to employees, can be communicated, $)
(Communicating options to employees, can be communicated, 0.5%)
(Communicating options to employees, can be communicated, $200,000)
---------------------
Text: page_label: 13
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
Exercise Price: Market Price vs. Discount  
When setting the exercise price for options, there are two
approaches: (1) set the price equal to the market price of
the stock at the time of grant, or (2) set the price at a
discount to the market price.  
Market Price:  
•Fair to employees and the company  
•No tax deduction for company
•Employees can sell immediately
•Employees can exercise immediately
Discount:
(Communication of options packages, recommended, dollar value)
(Communication of options packages, recommended against, percent of the company)
(Communication of options packages, effective when, dollar value)
---------------------
Text: page_label: 13
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
or (2) a dollar value based on the
current valuation; we encourage the latter when possible  
% $
“We are granting you options equivalent to
0.5% of the company’s equity”  
Considerations:  
•At an early stage, the only way
to communicate options grants given no true
valuation of the company  
•Hard for employees to grasp  what they
are really getting (“0.5% seems too little”)  
•Invites a negotiation  about what percent
of the company an employee really
deserves  “We are granting you options equivalent to
$200,000 of company stock”  
Considerations
(page_label, is, 12)
(file_path, is, /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf)
(5%, is, equivalent to)
(5%, is, $200,000 of company stock)
(Considerations, is, highly effective way to communicate the true value of an options grant)
---------------------
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.
Triplets:
(2018 FIFA World Cup, is, 21st FIFA World Cup)
(2018 FIFA World Cup, took place in, Russia)
(201
(HOW MUCH TO GRANT, Part II, )
---------------------
Text: page_label: 13
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
HOW MUCH TO GRANT  Part II
Triplets:
(HOW MUCH TO GRANT, Part II, )
---------------------
Text: page_label: 13
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
HOW MUCH TO GRANT  Part II
Triplets:
(HOW MUCH TO GRANT, Part II, )
---------------------
Text: page_label: 13
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
HOW MUCH TO GRANT  Part II
Triplets:
(HOW MUCH TO GRANT, Part II, )
----------------
(Two Approaches, is, reality)
(Creating an ESOP, requires, a combination of top-down and bottom -up planning)
(Decide the total amount of equity to be granted, is, part of creating an ESOP)
(Allocate these shares to employees over time, is, part of creating an ESOP)
(Decide the appropriate size of individual equity grants by position, is, part of creating an ESOP)
(Issue these shares as employees are hired, is, part of creating an ESOP)
---------------------
Text: page_label: 15
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
Two Approaches  
In reality, creating an ESOP will require a combination of
top-down and bottom -up planning  Top Down  Bottom Up  
Decide the total amount of
equity to be granted; allocate
these shares to employees
over time  Decide the appropriate size of
individual equity grants by
position; issue these shares as
employees are
(Top -Down Process, consists of, determining)
(Top -Down Process, consists of, creating)
(Top -Down Process, consists of, scheduling)
Text: page_label: 16
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
The Bottom -Up Process  
1.Determine the number of shares to be granted to each employee  
2.Determine the grant date  
3.Determine the vesting schedule  
Triplets:
(Bottom -Up Process, consists of, determining)
(Bottom -Up Process, consists of, determining)
(Bottom -Up Process, consists of, determining)
Text: page_label: 17
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
The Bottom -Up Process (continued)  
1.Determine the exercise price  
2.Determine the expiration date  
Triplets:
(Bottom -Up Process, consists
(page_label, is, 16)
(page_label, represents, how much equity to set aside in the esop)
(page_label, has, values of 15-20% for generally non-founder employees)
---------------------
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.
Triplets:
(The, 2018-19 budget for the Department of Energy, includes, $3.7 billion for the Office of Science)
(The, 2018-19 budget for the Department of Energy, is, an increase of $645 million over the 2018 enacted level)
(The, 2018-19 budget for the Department of Energy, represents, a 21.1% increase over the 2018 enacted level for the Office of Science)
---------------------
Text: The 2018
(page_label, is, 16)
(file_path, is, /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf)
(no, is, 0)
(technology emphasis, is, 0)
(geographic focus, is, region that is not considered a startup hub)
(hiring needs, are primarily, administrative or back -office team members)
(percentage of company issued to non founder employees, is between, 15% and 20%)
(founders, are, top managers, but hire others to fill key technical or functional roles)
(dna of the company, is, applying technology to a non -technical industry)
(geographic focus, is, either wholly or partially in a startup hub)
(hiring needs, are primarily, sales and marketing team members)
(founders, are not top managers in the business, or plan to step aside)
(dna of the company, is, technology, engineering, or data science)
(geographic focus, is, in a leading startup hub such as sf,
(page_label, is, 16)
(file_path, is, /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf)
(companies, issue, up to 25%)
(founders, are, top managers)
(founders, are not, top managers in the business, or)
(DNA, is, in applying technology to a non -technical industry)
(DNA, is, in technology, engineering, or data science)
(geographic focus, is, wholly or partially in a startup hub)
(geographic focus, is, in a leading startup hub such as SF, NYC or Boston)
(hiring needs, are, primarily sales and marketing team members)
(hiring needs, are, primarily engineering, development, or technical team members)
---------------------
Text: The 2018-19 season of the National Basketball Association (NBA) is the 72nd season of the National Basketball Association.
Triplets:
(2018-19 season, is, the 7
(Typical Distribution Schedule, consists of, Seniority)
(Typical Distribution Schedule, consists of, Equity Allocation)
(First, consists of, 10%)
(Next, consists of, 5%)
(Next, consists of, 5%)
(CTO, consists of, 1-5%)
(Key Developer or Engineer, consists of, 1-2%)
(Other Functional Team Member, consists of, 0.5-1.5%)
(No non -founding member of the senior team, should not exceed, 10%)
---------------------
Text: page_label: 18
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
3. Vesting Schedule  
•Four year vesting schedule is most common.  
•Cliff vesting is less common, but can be used to retain key employees.  
•Monthly vesting is less common, but can be used to align employee interests with company performance.  
Triplets:
(Vesting Schedule, is most common
(Bottom -Up Process, consists of, Segment your human resources)
(Bottom -Up Process, consists of, Create pay multipliers for each job function)
(Bottom -Up Process, consists of, Determine the dollar value of an options grant)
(Bottom -Up Process, consists of, Determine the current share price)
(Bottom -Up Process, consists of, Calculate options grants)
---------------------
Text: page_label: 19
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
The Top-Down Process  
1.Determine the total dollar amount to be spent on options  
2.Determine the number of shares to be reserved for options  
3.Determine the number of options to be granted  
4.Determine the exercise price  
5.Determine the vesting schedule  
Triplets:
(Top-Down Process, consists of, Determine the total dollar amount to be spent on options)
(Top-Down Process, consists of, Determine the number of shares to be reserved for options)
(Top-
(Segment Your Human Resources, is, segmentation)
(Segment Your Human Resources, has, Segment  Roles)
(Segment Your Human Resources, has, Award)
---------------------
Text: page_label: 20
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
2. Communicate Early and Often  
•Communicate the plan to all employees as soon as possible  
•Communicate the plan to all new hires as part of their orientation  
•Communicate the plan to all employees at least annually  
•Communicate the plan to all employees when there is a material change  
Triplets:
(Communicate Early and Often, is, communication)
(Communicate Early and Often, has, Communicate the plan to all employees as soon as possible)
(Communicate Early and Often, has, Communicate the plan to all new hires as part of their orientation)
(Communicate Early and Often, has, Communicate the plan to all employees at least annually)
(Communicate Early and Often,
(2, establish, Pay Multipliers for Each Role)
(Segment, Roles, 2)
(Segment, Award, ?)
---------------------
Text: page_label: 21
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
3. Establish Vesting Schedules  
Segment  Vesting Schedule  
in Years or %?
Triplets:
(3, establish, Vesting Schedules)
(Segment, Vesting Schedule, ?)
---------------------
Text: page_label: 22
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
4. Establish Performance Criteria  
Segment  Performance Criteria  
in % or $?
Triplets:
(4, establish, Performance Criteria)
(Segment, Performance Criteria, ?)
---------------------
Text: page_label: 23
file_path: /content/Documents/Employee-Stock-Option-
(page_label, is, 20)
(2, establish, Pay Multipliers for Each Role)
(Segment, is, Roles)
(Segment, is, Award)
(Segment, is, Options Multiplier)
(Segment, is, Founders)
(Segment, is, Co-Founders)
(Segment, is, %)
(Segment, is, Founding Team)
(Segment, is, Technical & Product)
(Segment, is, Early -Stage Hires)
(Segment, is, Senior Team)
(Segment, is, C-Level)
(Segment, is, Directors / VPs)
(Segment, is, Functional / Technical Team)
(Segment, is, Support Team)
(Segment, is, $)
(Segment, is, 0.5x)
(Segment, is, 1.0x)
(Segment, is, 0.25x)
(Segment, is, 0.5x)
(Segment, is, 0.1x)
(Segment, is, 0.0x)
(page_label, is, 2)
(Employee, Base Salary, x)
(Employee, Options, x)
(Employee, Options Multiplier, based on the employee’s role in HR segmentation schedule)
---------------------
Text: page_label: 21
file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf
3. Determine the Dollar Value of the Options Grant  
Employee  
Base Salary  = x Options  
Multiplier  Dollar Value  
of Options Grant  Base Salary as negotiated with
the employee at the time of hire
or promotion  
Options Multiplier is decided
based on the employee’s role in
the HR segmentation schedule
Triplets:
(Employee, Base Salary, x)
(Employee, Options, x)
(Employee, Options Multiplier, based on the employee’s role in HR segmentation schedule)
---------------------
Text: page_label: 21
file_path: /content/Documents/Employ


通过构建查询引擎来查询知识图谱


query = "What is ESOP?""What is ESOP?"
query_engine = index.as_query_engine(include_text=True,
                                     response_mode ="tree_summarize",
                                     embedding_mode="hybrid",
                                     similarity_top_k=5,)
#
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>
<|user|>
Question: {query}
Helpful Answer:
</s>"""
#
response = query_engine.query(message_template)
#
print(response.response.split("<|assistant|>")[-1].strip())
#####OUTPUT #####################
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.


query ="Who is Atul?""Who is Atul?"
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>
<|user|>
Question: {query}
Helpful Answer:
</s>"""
#
response = query_engine.query(message_template)
#
print(response.response.split("<|assistant|>")[-1].strip())
################OUTPUT#####################
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.


图形可视化


  • pyvis 库用于知识图谱的图形表示
  • notebook=True 确保图表与 Jupyter 笔记本的兼容性
  • cdn_resources="in_line" 指定资源的内联排列
  • directed=True 指定图形为有向图的条目


from pyvis.network import Network
from IPython.display import display
g = index.get_networkx_graph()
net = Network(notebook=True,cdn_resources="in_line",directed=True)
net.from_nx(g)
net.show("graph.html")
net.save_graph("Knowledge_graph.html")
#
import IPython
IPython.display.HTML(filename="/content/Knowledge_graph.html")


8


9


10


数据持久性


数据保留发挥着至关重要的作用,特别是当你的知识图谱和相关索引复杂或构建它们需要了巨大的计算工作时。


通过持久化数据,我们可以轻松地检索数据以供将来分析,而无需完全重建。


storage_context.persist()


保存包含以下信息的文件夹


11


结论


总的来说,向量数据库和知识图谱之间的区别在于它们存储和表征数据的方法。向量数据库擅长基于相似性的操作,依靠数值向量来衡量实体之间的距离。另一方面,知识图谱旨在捕捉复杂的关系和依赖关系,通过节点和边来促进语义分析和高级推理。


对于语言模型(LLM)的幻觉现象,知识图谱比向量数据库更有优势。知识图谱提供的信息更准确、多样、有趣、逻辑性和一致性强,降低了LLM中出现幻觉的可能性。这种优势来自于它们提供关于实体间关系的精确细节,而不仅仅是指出相似性,从而支持更复杂的查询和逻辑推理。


总之,向量数据库和知识图谱都有各自的优势和劣势,最优选择取决于具体的使用案例。理解数据的性质和项目要求对于决定使用向量数据库还是知识图谱作为存储和表征手头信息的更合适方法至关重要。

文章来源:https://medium.com/dphi-tech/implement-rag-with-knowledge-graph-and-llama-index-6a3370e93cdd
欢迎关注ATYUN官方公众号
商务合作及内容投稿请联系邮箱:bd@atyun.com
评论 登录
写评论取消
回复取消