通过使用大型语言模型(LLM)的辅助自动提高其准确性的网站链接

社区文章 发布于2025年4月12日

网站内部链接通过连接相关内容来增强导航和用户体验。这种连接性确保用户可以轻松浏览不同部分而不会迷失,最终提高参与度和满意度。

每个网站管理员都应该将一个页面中的各种术语链接到网站内的相关页面,并进行反向链接。这可以提高排名,并让用户更容易在您的网站上找到相关信息。

更重要的是,内部链接通过引导访问者浏览网站的不同部分来帮助促进产品或服务的销售。特别是对于信息网站,正确使用内部链接可以通过帮助用户更好地理解他们正在阅读的内容,大大增强用户体验。

现在想象一下,创建一个新页面需要我费尽心力地搜索无数条目,只为了将它们适当地链接起来?这并不是什么高深莫测的技术,而是一项极其考验耐心的工作——或者说,看起来是这样,直到你意识到这项琐碎的任务浪费了多少时间。

我的意思是,谁知道管理一个在线存在会是如此受虐狂且枯燥乏味的例行工作?

单个网页可以包含十到三十个关键术语,这些术语既可以内部链接到站点内,也可以外部链接。

查找相关信息是一项极其耗时的任务!

YouTube Video

工作流:使用大型语言模型嵌入进行语义搜索

此工作流概述了使用大型语言模型(LLM)嵌入实现语义搜索的过程。目标是在网页上创建智能链接,根据上下文自动将用户连接到最相关的内容。

步骤

  1. 数据存储设置:

    • 利用 PostgreSQL 及其向量数据类型,高效地存储和管理 LLM 生成的文本嵌入。
  2. 文本分块:

    • 将所有网站页面文本划分为可管理的块或段进行处理。
  3. 嵌入生成:

    • 使用大型语言模型为每个文本块生成嵌入(向量表示)。
  4. 模板标记创建:

    • 开发模板标记,以识别页面中需要语义链接的特定术语。
  5. 标记插值和链接程序:

    • 实现自动化程序来处理这些标记的术语。
      1. 将每个标记的术语转换为其对应的 LLM 嵌入。
      2. 使用相似性度量(例如,余弦相似性)将此嵌入与数据库中所有存储的嵌入进行比较。
      3. 根据最高的相似性得分识别最相关的页面。
    • 在原始内容中自动添加指向此最相关页面的链接。

优点

  • 增强用户体验:用户被引导到高度上下文相关的知识,从而改善导航和对复杂主题的理解。
  • 效率:自动化创建语义链接的过程,减少了人工工作量,同时保持了准确性。

在此解释中,我不会详细介绍数据存储设置、文本分块或生成嵌入。但是,如果您有兴趣了解更多这些主题或需要 PostgreSQL 设置方面的具体帮助,请随时联系我——我很乐意提供帮助!

模板标记创建

我的 Emacs RCD 模板插值系统包有助于使用插值函数,并允许我自定义标记。

按照标准,我使用以下标记来插入模板标签 ⟦ (lisp-command "Something") ⟧

作为一名主要使用 Emacs Lisp 的用户,我想指出,类似的模板和字符串插值功能存在于各种编程语言中,例如 Python 或您可能使用的其他语言。如果您对它在另一种特定语言中的工作原理感到好奇,请随时向 LLM 寻求指导!

我喜欢这些特殊的分隔符,因为它们在标记和文本中不常使用

  1. 用于开启分隔符 - 数学右白方括号
  2. 用于关闭分隔符 - 数学左白方括号

我正在寻找一种方法,在各种类型的标记文档(如 Markdown、Org mode 或 Asciidoctor)中添加变量和 Lisp 代码的插值。通常,这涉及先使用插值,然后使用这些标记之一。

然而,在我的情况下,我不需要任何变量或代码插值;我只想要简单的文本格式化和标记。因此,我计划使用以下分隔符

(defcustom rcd-template-any-delimiter-open "〈"
  "The opening delimiter for RCD Template Interpolation System."
  :group 'rcd
  :type 'string)

(defcustom rcd-template-any-delimiter-close "〉"
  "The closing delimiter for RCD Template Interpolation System."
  :group 'rcd
  :type 'string)

那么现在它是如何实际使用的呢?

想象一下,我正在写这段(正是这段)关于〈Emacs Lisp〉的文字。为了突出显示一段文本——选择它以转换为“通用语义链接”——我导航到“Emacs Lisp”字样,将其标记,然后使用一个函数(可能由按键绑定触发)将这些选定的术语用特定分隔符括起来。

您可以在那里看到我它是如何做到的:〈Emacs Lisp〉。字符串前或后的空格应该无关紧要。

用分隔符括起来的词或术语将被转换为嵌入。然后,这些嵌入将与数据库中存储的对应于网站的相同部分、特定页面集或外部链接的嵌入进行比较。

我的个人功能如下


(defun wrs-area-pages-by-embeddings (&optional limit link)
  "Search for pages in the current Hyperscope or selected website area
based on embeddings similarity to a given query. Optionally LIMIT the
number of results.

This function performs an embedding-based search within a specified
area, using either the currently active table's associated hyperscope or
allowing selection from available areas if none is set. It retrieves IDs
of objects with similar embeddings and displays them in Hyperscope mode.

- LIMIT: Optional argument to restrict the number of returned items (not
  used directly by this function but can be passed through).

The query for similarity search is derived either from selected text or
user input, then converted into an embedding using
`rcd-llm-get-embedding-single'. The SQL subquery calculates similarities
between embeddings and groups them accordingly. Results are ordered by
the minimum similarity within each group.

If any matching IDs `id-list' are found, they will be opened in
Hyperscope mode with a formatted query description as context."
  (interactive)
  (let* ((query (or (rcd-region-string) (rcd-ask-get "Query: ")))
     (query (rcd-llm-get-embedding-single query))
     (limit (or limit 10))
     (area (cond ((and rcd-db-current-table-id (hyperscope-area rcd-db-current-table-id))
              (hyperscope-area rcd-db-current-table-id))
             (t (wrs-areas-select))))
     (id-list (rcd-sql-list
           "SELECT subquery.embeddings_referencedid
FROM (
    SELECT e.embeddings_referencedid,
           e.embeddings_embeddings <=> $1 AS similarity
    FROM embeddings e
    JOIN hyobjects h ON e.embeddings_referencedid = h.hyobjects_id
    WHERE e.embeddings_embeddingtypes = 1
      AND e.embeddings_embeddings <=> $1 < 0.5
      AND h.hyobjects_areas = $2
    ORDER BY similarity ASC
    LIMIT $3
) AS subquery
GROUP BY subquery.embeddings_referencedid
ORDER BY MIN(subquery.similarity) ASC"
           rcd-db query area limit)))
    (cond ((and link id-list) (wrs-insert-lightweight-markup-hyperlink (car id-list)))
      (id-list (hyperscope-by-id-list id-list (format "Query: %s" query)))
      (t (rcd-message "Matches not found")))))
      

然后是更高级的函数,在模板插值上运行它

(defun wrs-semantic-link (query)
  "Generate a semantic link using embeddings.

This function creates a semantic link by leveraging the
`wrs-area-pages-by-embeddings' function. It does not require any
arguments and is intended to be used interactively. When called, it
processes text in region based on their embeddings and inserts
appropriate links."
  (let* ((id (wrs-area-pages-by-embeddings query nil t))
     (link (hyperscope-url-link id)))
    (cond ((and link (rcd-string-not-empty-p link)) (format "[%s](%s)" query link))
      (t query))))

(defun wrs-semantic-link-region ()
  "Interactively replaces the current selected text with a semantic link
using `wrs-semantic-link' function. If no region is active, does
nothing.

The function uses `rcd-region-string' to get the currently selected text
and stores it in variable `region'. It then checks if there is any
content in this variable; if not, execution stops here without further
action.

Finally, replaces the original selected text with content from
`interpolated' utilizing helper function `rcd-region-string-replace'."
  (interactive)
  (let ((region (rcd-region-string)))
    (when region
      (let ((interpolated (rcd-template-eval-any region #'wrs-semantic-link)))
    (rcd-region-string-replace interpolated)))))

但是现在如何使用这个功能呢?

  1. 文本中的术语必须进行标记,例如这里:〈Emacs Lisp〉是LISP编程语言的一种方言,由〈GNU Emacs〉文本编辑器用于扩展和定制其功能。

  2. 文本由来自 Emacs 的 RCD 模板插值系统rcd-template-eval-any 函数进行插值,具体如何操作取决于文本处理。

  3. 任何标记的术语都会在适当的标记中接收其链接,无论是什么标记。

值得注意的是,除了突出显示文本中的特定术语外,所需的人工干预极少。该系统能够自动将这些突出显示的术语适当地链接起来,而无需人员的额外输入。

让我创建一个 Emacs Lisp 区域函数来演示它的工作原理……

示例文本

  1. Emacs 输入法提供了一种输入各种书写系统和语言字符的方式。

    **...然后标记...*

  2. 〈Emacs 输入法〉 提供了一种输入各种书写系统和语言字符的方式。

    ...接着是语义链接...

  3. [Emacs 输入法](https://gnu.support/gnu-emacs/emacs-lisp/Emacs-Lisp-input-method-for- FULLWIDTH-LATIN-LETTERS.html) 提供了一种输入各种书写系统和语言字符的方式。

这里可以显示为源

3. [Emacs input
   methods](https://gnu.support/gnu-emacs/emacs-lisp/Emacs-Lisp-input-method-for-
   FULLWIDTH-LATIN-LETTERS.html) provide a way to
   input characters from various writing systems and languages.

让我们说,我们正在谈论〈大型语言模型〉

Let us say, we are speaking of [Large Language Models](https://gnu.support/large-language-models-llm/index.html):

需要注意的是,我,也就是作者,不再查找链接了,我把它留给系统来决定。

我的工作是标记那些我希望通过语义搜索进行超链接的术语。

这些语义化的网站链接如何自动提高其准确性?

您撰写的网站页面越多,添加的语义内容就越多,从而提高匹配准确性。随着每个页面更新,语义链接可能会发生变化,这些变化可以通过您自己的算法进行验证和优化,以获得更高的精度。

自动化链接建设是网站管理员的强大工具;它需要人工监督来标记相关文本,但显著减少了链接搜索和手动更新等繁琐任务。

此外,如果任何 URL 发生更改,它们会自动在所有网站页面上更新。本文旨在为开发人员提供可以在自己的项目中实现的概念。

参考

社区

注册登录 评论