幻觉是在处理大型语言模型(LLMs)时常见的问题。LLMs生成流畅连贯的文本,但经常产生不准确或不一致的信息。防止LLMs中出现幻觉的一种方法是使用外部知识源,如提供事实信息的数据库或知识图谱。
向量数据库是什么?向量数据库是一组高维向量的集合,用于表示实体或概念,例如单词、短语或文档。向量数据库可以根据实体或概念的向量表示来度量它们之间的相似性或关联性。
举个例子,向量数据库可以告诉你“巴黎”和“法国”比“巴黎”和“德国”更相关,基于它们的向量距离。
知识图谱是什么?知识图谱是一组节点和边,用于表示实体或概念以及它们之间的关系,例如事实、属性或类别。
知识图谱可以根据节点和边的属性来查询或推断不同实体或概念的事实信息。
举个例子,知识图谱可以告诉你“巴黎”是“法国”的首都,基于它们的边标签。
查询图数据库涉及遍历图结构并根据特定标准检索节点、关系或模式。下面是一个简单的示例,展示了如何查询图数据库:
假设你有一个代表社交网络的图数据库,其中用户是节点,而它们的关系(例如友谊)由连接节点的边表示。你想要找到给定用户的朋友圈(共同的连接)。
从参考用户开始:
在图数据库中,通过查询特定的用户标识符或其他相关标准来识别代表参考用户的节点。
遍历图:
使用图形查询语言(如Neo4j中使用的Cypher或Gremlin)从参考用户节点遍历图。编写一个查询,指定要探索的模式或关系。在这种情况下,您想要找到朋友的朋友。示例Cypher查询:
MATCH (:User {userId: ‘referenceUser’})-[:FRIEND]->()-[:FRIEND]->(fof:User)
RETURN fof
这个查询从参考用户开始,沿着FRIEND关系找到另一个节点(朋友),然后再沿着另一个FRIEND关系找到朋友的朋友(fof)。
检索结果:
在图数据库上执行查询,根据查询模式检索出相应的节点(朋友的朋友)。如果需要,还可以获取检索到的节点的特定属性或附加信息。
呈现结果:
将检索到的朋友的朋友显示给用户或按照需求进一步处理数据。这些信息可以用于建议、网络分析或其他相关目的。
图数据库提供了更高级查询功能,包括过滤、聚合和复杂模式匹配。具体的查询语言和语法可能有所不同,但总体过程涉及遍历图结构以检索与所需条件匹配的节点和关系。
查询向量数据库通常涉及搜索相似向量或根据特定条件检索向量。以下是查询向量数据库的简单示例:
假设你有一个包含客户配置文件的向量数据库,这些配置文件表示为高维向量,
你想找到与给定参考客户相似的客户。
定义参考客户向量:
首先,为参考客户定义一个向量表示。这可以通过提取相关特征或属性并将它们转换为向量格式来完成。
执行相似性搜索:
使用合适的算法,如k-最近邻(k-NN)或余弦相似度,在向量数据库中执行相似性搜索。该算法将根据相似性分数识别参考客户向量的最近邻居。
检索相似客户:
检索与上一步中识别的最近邻居向量对应的客户配置文件。这些配置文件将根据定义的相似性度量表示与参考客户相似的客户。
呈现结果:
最后,将检索到的客户配置文件或相关信息呈现给用户,例如显示他们的名字、人口统计信息或购买历史。此信息可用于推荐、定向营销活动或个性化体验。
知识图谱的主要组成部分。
知识图谱通常由两个主要组件组成:
顶点/节点:表示知识领域中的实体或对象。每个节点对应一个唯一的实体,并由唯一的标识符进行标识。例如,在关于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)
知识图谱数据库可以通过存储三元组来高效地存储和查询复杂的图数据
知识图谱相对于向量数据库在LLM幻觉方面的优势是什么?
相比于向量数据库,知识图谱提供了更精确和具体信息。向量数据库表示两个实体或概念之间的相似性或关联性,而知识图谱能够更好地理解它们之间的关系。例如,知识图谱可以告诉你“埃菲尔铁塔”是“巴黎”的地标,而向量数据库只能表示这两个概念的相似程度。这可以帮助LLM生成更准确和相关的文本。
知识图谱支持比向量数据库更多样化和复杂的查询。向量数据库主要基于向量距离、相似度或最近邻来回答问题,这些仅限于直接相似度测量。相比之下,知识图谱可以处理基于逻辑运算符(如“具有属性Z的所有实体是什么?”或“W和V的共同类别是什么?”)的查询。这可以帮助LLM生成更多样化和有趣的文本。
知识图谱比向量数据库能够进行更多的推理和推断。向量数据库只能提供直接存储在数据库中的信息。相比之下,知识图谱可以从实体或概念之间的关系推导出间接信息。例如,知识图谱可以根据“巴黎是法国的首都”和“法国位于欧洲”的事实推断出“埃菲尔铁塔位于欧洲”。这可以帮助LLM生成更符合逻辑和一致的文本。
总之,对于LLM中的幻觉问题,知识图谱是一个比向量数据库更好的解决方案。知识图谱为LLM提供了更准确、相关、多样化、有趣、逻辑和一致的信息。因此,使用知识图谱可以减少LLM中的幻觉,使其在生成准确和真实的文本时更加可靠。但关键是文档需要清楚地展示关系,否则知识图谱将无法捕捉到它。
矢量数据库和知识图谱采用两种不同的方法来存储和表示数据。
矢量数据库方法使用数值向量来表示数据,主要用于相似性搜索。
每个实体都表示为一个高维向量,实体之间的相似性根据向量距离进行计算。
矢量数据库非常适合基于相似性的操作,但可能难以表示实体之间的复杂关系和语义含义。相比之下,知识图谱是为了捕捉和表示对象之间的关系而构建的。
知识图谱捕捉实体之间的复杂关系和依赖关系,并提供语义分析和推理能力。知识图谱可以根据逻辑运算符回答复杂的查询,并执行高级推理和知识发现。图数据库主要关注对象之间的成对关系,而矢量数据库则关注向量的相似程度。
数据的存储方式也完全不同,
图数据库
图数据库利用节点和边来表示关系,适合分析实体之间的关系和复杂网络。矢量数据库
而矢量数据库使用数值数组。矢量数据库非常适合相似性搜索和最佳匹配搜索。选择哪种方法取决于几个重要因素,如数据的性质和关系、查询和分析的要求以及在相似性搜索或关系探索方面的效率。两种方法都有自己的优势和劣势,具体的使用情况将决定哪种最适合。
主要比较因素:
数据结构:数据存储方式完全不同,图数据库构建用于存储节点和边,非常擅长映射关系,将其视为一等公民。矢量数据库将数据存储为数值数组。数据检索和分析:图数据库构建用于分析实体之间的关系,而矢量数据库擅长分析模式。查询:图数据库查询实体之间的关系和复杂网络。矢量数据库非常适合相似性搜索或最佳匹配搜索。性能:基于查询重点,图数据库/知识图谱在处理涉及关系的查询方面非常出色,而矢量数据库提供快速的相似性搜索。
比较图数据库和矢量数据库时,需要考虑几个重要问题。以下是一些关键问题供探讨:
数据的性质和关系是什么?数据主要由结构化信息还是非结构化信息组成?实体之间是否存在复杂的关系和依赖关系?查询和分析的具体要求是什么?是否需要高效的相似性搜索和推荐?是否需要进行复杂的图遍历和关系探索?语义分析和推理能力是否至关重要?对于实时应用,低延迟是否关键?是否有多种类型的关系和属性需要捕获?可用的查询语言、API和生态系统集成有哪些?
总之,矢量数据库和知识图谱使用不同的方法来存储和表示数据。虽然矢量数据库适合基于相似性的操作,但知识图谱旨在捕捉和分析复杂的关系和依赖关系。选择合适的方法取决于项目的具体需求和目标。
代码实现:
技术栈使用:LlamaIndex:LlamaIndex是一个编排框架,用于简化将私有数据与公共数据集成以构建使用大型语言模型(LLMs)的应用程序。它提供了数据摄取、索引和查询的工具,使其成为生成式AI需求的一种多功能解决方案。2. 嵌入模型:嵌入模型需要将文本转换为所提供文本的信息的数字表示形式。该表示形式捕获了所嵌入内容的语义含义,使其适用于许多行业应用。在这里,我们使用了“thenlper/gte-large”模型。3. LLM:大型语言模型需要根据提供的问题和上下文生成响应。在这里,我们使用了Zephyr 7B beta模型。
逐步代码实现:此代码实现将引导您创建使用Llama Index的知识图谱。
-
我们将读取一个.pdf文件并将其转换为结构化知识图谱。
-
将嵌入存储在图数据存储库中。
-
检索与用户查询匹配的相关上下文。
-
向llm提供响应以生成响应。
实现步骤:
安装所需依赖项。
pipinstall llama_index pyvis Ipython langchain pypdf
启用诊断日志记录日志记录提供了对代码执行的有价值的见解。在这里,日志级别设置为“信息”,这将输出有助于监视应用程序操作流程的消息。
importloggingimportsys#logging.basicConfig(stream=sys.stdout, level=logging.INFO)logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
导入所需的依赖项
fromllama_indeximport(SimpleDirectoryReader,LLMPredictor,ServiceContext,KnowledgeGraphIndex)#fromllama_index.graph_storesimportSimpleGraphStorefromllama_index.storage.storage_contextimportStorageContextfromllama_index.llmsimportHuggingFaceInferenceAPIfromlangchain.embeddingsimportHuggingFaceInferenceAPIEmbeddingsfromllama_index.embeddingsimportLangchainEmbeddingfrompyvis.networkimportNetwork
简洁概述所使用的包:
SimpleDirectoryReader:用于读取非结构化数据。
LLMPredictor:用于使用大型语言模型(LLM)生成预测。
ServiceContext:提供协调各种服务所需的上下文数据。
KnowledgeGraphIndex:用于构建和操作知识图谱。
SimpleGraphStore:用作存储图数据的简单仓库。
HuggingFaceInferenceAPI:用于利用开源LLM的模块。
安装LLM
在这里,我们使用了Huggingface推理API endpoint.
HF_TOKEN ="Your Huggaingface api key "llm = HuggingFaceInferenceAPI(model_name="HuggingFaceH4/zephyr-7b-beta", token=HF_TOKEN)
安装embedding 模型
embed_model = LangchainEmbedding(HuggingFaceInferenceAPIEmbeddings(api_key=HF_TOKEN,model_name="thenlper/gte-large"))
装载数据
documents = SimpleDirectoryReader("/content/Documents").load_data()print(len(documents))
构建知识图谱索引创建知识图谱通常涉及专门的复杂任务。然而,通过利用LLaMa索引(LLM)、KnowledgeGraphIndex和GraphStore,我们可以从Llama Hub支持的任何数据源中方便地构建相对有效的知识图谱。
setup the service contextservice_context=ServiceContext.from_defaults(chunk_size=256,llm=llm,embed_model=embed_model)#setup the storage contextgraph_store=SimpleGraphStore()storage_context=StorageContext.from_defaults(graph_store=graph_store)#Construct the Knowlege Graph Undexindex=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: 2file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfWhat is an ESOP?Triplets:(page_label, is, 2)(ESOP, is, What is an ESOP?)---------------------Text: page_label: 3file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfWhy Offer an ESOP?Triplets:(page_label, is, 3)(ESOP, is, Why Offer an ESOP?)---------------------Text: page_label: 4file_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: 5file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfWhat is an ESOP?•An Employee Stock Options Plan (ESOP)•An allocation of shares that will be granted to employees in the futurein the form of stock options–How much equity should wesetasideforemployees?•A planforhow these options will bedistributed:–How many shares will individual employees receive?–What terms will govern thesegrants?•The planisasimportantasthe allocation!Triplets:(ESOP,is, allocation)(ESOP,is, plan)(ESOP,is, important)---------------------Text: page_label:6file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-(Option,is, effectiveformofequity ownership)(Option, has, intrinsicvalue)(Option,is,locked-inpriceforshares)---------------------Text: page_label:1file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfWhatisan ESOP?•Whatisan ESOP?–A qualified retirement plan–A tax-qualified defined contribution plan–A plan thatisprimarily designedtoprovide retirement benefitstoemployees–A plan thatisprimarily designedtoprovide benefitsintheformofstock–A plan thatisprimarily designedtoprovide benefitsintheformofstock–A plan thatisprimarily designedtoprovide benefitsintheformofstock–A plan thatisprimarily designedtoprovide benefitsintheformofstock–A plan thatisprimarily designedtoprovide benefitsintheformofstock–A plan thatisprimarily designedtoprovide benefitsintheformofstock–(Option,is,righttopurchase)(Option,is,setprice)(Option,is, certainperiodoftime)---------------------Text: page_label:1file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfWhatisan ESOP?•Whatisan ESOP?–A qualified retirement plan–A tax-qualified plan that meetsERISA requirements–A plan thatisprimarily designedtoprovide retirement benefitstoemployees–A plan thatisprimarily designedtoprovide benefitsintheformofemployer securities–A plan thatisprimarily designedtoprovide benefitsintheformofemployer securities thatareacquiredthroughpurchase,receiptfroma corporateparent,orthroughthe accumulationofdistributionsonemployer securities–A plan thatisprimarily designedtoprovide benefitsintheformofemployer securities thatareacquiredthroughthe accumulationof(LifecycleofaStartupESOP, involves, foundersandearly investors)(LifecycleofaStartupESOP, involves,managementandthe BoardofDirectors)(LifecycleofaStartupESOP, 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:11file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfLifecycleofaStartupESOP•Found(Common Termsinan OptionsPackage,is,NumberofShares)(Common Termsinan OptionsPackage,is, Strike Price)(Common Termsinan OptionsPackage,is, Vesting Schedule)(Common Termsinan OptionsPackage,is, CliffPeriod)(Common Termsinan OptionsPackage,is, ExpirationDate)---------------------Text: page_label:1file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfExecutive SummaryThisdocumentoutlines the best practicesfordesigningandimplementing an employee stockoptionplan (ESOP)foraprivatecompany. Thedocumentisintendedtoprovide a frameworkfordesigning an ESOP thatistailoredtothe specific needsofthe companyandits employees. Thedocumentisnotintendedtobe a comprehensive guidetoESOP design, but rather ahigh-leveloverviewofthekeyconsiderations that should be takenintoaccountwhendesigning an ESOP.Triplets:(Executive Summary,is,High-leveloverview)(Executive Summary,is,Keyconsiderations)(Executive Summary(Why Issue OptionstoEmployees?, attracts, top recruits)(Why Issue OptionstoEmployees?, retains, employees)(Why Issue OptionstoEmployees?, aligns, incentives)(Why Issue OptionstoEmployees?, rewards,valuecreation)(Why Issue OptionstoEmployees?, encourages,long-term thinking)---------------------Text: page_label:10file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfHow Should Options Be Granted?•AttheRightTime: options should be grantedattherighttimeinthecompany’s lifecycle,whenthe company has achieved a certainlevelofsuccessandthevalueofthe companyisclear•AttheRightPrice: options should be grantedata fair price, basedonthe company’s valuationatthetimeofgrant•AttheRightSize: options should be grantedintherightsize, basedonthe employee’sroleandcontributiontothe companyTriplets:((Startups,are,uniquecase)(Startups,use, options)(Startups, seekingtoachieve,bigexit)---------------------Text: page_label:10file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfThe definingdifferencebetweenSilicon Valley companiesandalmostevery other industryinthe U.S.Isthe virtually universal practice amongtech companiesofdistributing meaningful equity (usuallyintheformofstock options)toordinary employees . A Defining CharacteristicofStartupCultureSteven Johnson, Technology Writer•Startupsareauniquecase. Unlikeatlarger corporations, employeeownershipisan essentialelementofstartupcommunitiesandculture–Ashigh-risk/high-reward enterprises, startupsuseoptionstoalignemployee compensationwiththe risk -prone mentalityofthebusiness–Startups seekingtoachieve a “bigexit”useoptionstoalignallemployeestodrive toward this desired outcomeTriplets:(Startups(ESOP,is, necessary partof, capital structure)(VCs, require, ESOPs)(Startups,arecompelled,tooffer, options packages)---------------------Text: page_label:11file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfThe ESOPasa RecruitmentandRetentionTool•ESOPsareacriticaltoolforrecruitingandretaining employees–Ina competitive job market, ESOPs can be usedtoattract top talent–Ina tight labor market, ESOPs can be usedtoretainkeyemployees–Ina volatile market, ESOPs can be usedtoretain employees duringa downturn–Inahigh-growth company, ESOPs can be usedtoretain employees duringaperiodofrapid expansion–Ina companywithahighemployee turnover rate, ESOPs can be usedtoreduce turnoverandassociated costs–Ina companywithahighexecutive turnover rate, ESOPs can be usedto(page_label:11,is, stage)(stage,is, pre-seed)(stage,is,seed)(stage,is, early -vc)---------------------Text: page_label:11file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfpage_label:12file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfpage_label:13file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfpage_label:14file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfpage_label:15file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices(ESOP,isnecessaryfor, Pre-seed)(ESOP,isnotnecessaryfor, Pre-seed)(ESOP, can be helpfulfor, Pre-seed)(ESOP,isnotnecessaryfor,Seed)(ESOP,isrequiredfor, Early -VC)(ESOP, must be createdfor, Early -VC)(ESOP, servesasa guidelinefor, Early -VC)(ESOP,isimportanttohave standardizedfor, Late-VC)(ESOP,isgonefor, Growth)(ESOP, shares remainingaremore valuablefor, Growth)(ESOP,isusedtoallownewhirestoshareinthe upsidefor, Growth)(ESOP, should besetupbetween, Pre-seedand, Early -VC)---------------------Text: page_label:12file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfHow Much Equity Should YouGrant?Stage Considerations TakeawayPre-seedFound(Communicating optionstoemployees, can be communicated, % versus $)(Communicating optionstoemployees, can be communicated, %)(Communicating optionstoemployees, can be communicated, $)(Communicating optionstoemployees, can be communicated,0.5%)(Communicating optionstoemployees, can be communicated, $200,000)---------------------Text: page_label:13file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfExercise Price: Market Price vs. DiscountWhensetting the exercise priceforoptions, therearetwoapproaches: (1)setthe price equaltothe market priceofthe stockatthetimeofgrant,or(2)setthe priceatadiscounttothe market price.Market Price:•Fairtoemployeesandthe company•Notax deductionforcompany•Employees can sell immediately•Employees can exercise immediatelyDiscount:(Communicationofoptions packages, recommended, dollarvalue)(Communicationofoptions packages, recommended against,percentofthe company)(Communicationofoptions packages, effectivewhen, dollarvalue)---------------------Text: page_label:13file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfor(2) a dollarvaluebasedonthecurrentvaluation; we encourage the latter when possible% $“We are granting you options equivalent to0.5% of the company’s equity”Considerations:•At an early stage, the only wayto communicate options grants given no truevaluation of the company•Hard for employees to grasp what theyare really getting (“0.5% seems too little”)•Invites a negotiation about what percentof the company an employee reallydeserves “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 optionsgrant)---------------------Text: The2018FIFA World Cup was the21st 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: 13file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfHOW MUCH TO GRANT Part IITriplets:(HOW MUCH TO GRANT, Part II, )---------------------Text: page_label: 13file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfHOW MUCH TO GRANT Part IITriplets:(HOW MUCH TO GRANT, Part II, )---------------------Text: page_label: 13file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfHOW MUCH TO GRANT Part IITriplets:(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: 15file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfTwo ApproachesIn reality, creating an ESOP will require a combination oftop-down and bottom -up planning Top Down Bottom UpDecide the total amount ofequity to be granted; allocatethese shares to employeesover time Decide the appropriate size ofindividual equity grants byposition; issue these shares asemployees are(Top -Down Process, consists of, determining)(Top -Down Process, consists of, creating)(Top -Down Process, consists of, scheduling)Text: page_label: 16file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfThe Bottom -Up Process1.Determine the number of shares to be granted to each employee2.Determine the grant date3.Determine the vesting scheduleTriplets:(Bottom -Up Process, consists of, determining)(Bottom -Up Process, consists of, determining)(Bottom -Up Process, consists of, determining)Text: page_label: 17file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfThe Bottom -Up Process (continued)1.Determine the exercise price2.Determine the expiration dateTriplets:(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: 18file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf3. 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: 19file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdfThe Top-Down Process1.Determine the total dollar amount to be spent on options2.Determine the number of shares to be reserved for options3.Determine the number of options to be granted4.Determine the exercise price5.Determine the vesting scheduleTriplets:(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: 20file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf2. 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 changeTriplets:(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: 21file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf3. Establish Vesting SchedulesSegment Vesting Schedulein Years or %?Triplets:(3, establish, Vesting Schedules)(Segment, Vesting Schedule, ?)---------------------Text: page_label: 22file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf4. Establish Performance CriteriaSegment Performance Criteriain % or $?Triplets:(4, establish, Performance Criteria)(Segment, Performance Criteria, ?)---------------------Text: page_label: 23file_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: 21file_path: /content/Documents/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf3. Determine the Dollar Value of the Options GrantEmployeeBase Salary = x OptionsMultiplier Dollar Valueof Options Grant Base Salary as negotiated withthe employee at the time of hireor promotionOptions Multiplier is decidedbased on the employee’s role inthe HR segmentation scheduleTriplets:(Employee, Base Salary, x)(Employee, Options, x)(Employee, Options Multiplier, based on the employee’s role in HR segmentation schedule)---------------------Text: page_label: 21file_path: /content/Documents/Employ
通过构建查询引擎来查询知识图谱
query ="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.<|user|>Question: {query}Helpful Answer:"""#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?"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.<|user|>Question: {query}Helpful Answer:"""#response = query_engine.query(message_template)#print(response.response.split("<|assistant|>")[-1].strip())################OUTPUT#####################Idonothave prior knowledgeorcontext about who atul is. Please provide more informationorcontext so I can assist you better. Without any further context, Idonotknow the answer to your question.
图可视化pyvis库用于知识图谱的图形表示notebook=True确保图形与Jupyter笔记本兼容cdn_resources="in_line"指定资源的内联排列directed=True将图指定为有向图。
frompyvis.networkimportNetworkfromIPython.displayimportdisplayg = 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")#importIPythonIPython.display.HTML(filename="/content/Knowledge_graph.html")
数据持久性数据保留起着重要作用,特别是当你的知识图谱和相关索引复杂或需要大量计算资源来构建时。
通过持久化数据,我们可以在无需完全重建的情况下轻松检索未来分析所需的数据。
storage_context.persist()
保存一个包含以下信息的文件夹
总结总的来说,向量数据库和知识图谱的区别在于它们存储和表示数据的方法。向量数据库擅长基于相似性操作,依靠数值向量来测量实体之间的距离。另一方面,知识图谱通过节点和边来捕捉复杂的关系和依赖性,促进语义分析和高级推理。
对于语言模型(LLM)幻觉,知识图谱被证明优于向量数据库。知识图谱提供更准确、多样化、有趣、逻辑和一致的信息,减少了LLM中出现幻觉的可能性。这种优越性源于它们能够提供关于实体之间关系的精确细节,而不仅仅是表示相似性,支持更复杂的查询和逻辑推理。
每种方法的有效性取决于数据的具体性质、关系的复杂性和期望的结果。作为知识图谱基础的图数据库在分析关系和复杂网络方面表现出色。向量数据库以其数字数组在相似性搜索和最佳匹配场景中表现出色。最终,两者之间的选择取决于项目的需求,包括数据的性质、关系探索的需要以及预期的查询类型。
做出选择时需要考虑的关键因素包括数据的性质和关系、复杂依赖关系的存在、查询和分析需求、高效相似性搜索的需要以及实时应用考虑。此外,还应考虑查询语言、API和生态系统集成的可用性。
总之,向量数据库和知识图谱各有优势和劣势,最佳选择取决于具体的用例。了解数据的性质和项目需求是确定向量数据库还是知识图谱更适合存储和表示手头信息的关键。