AlessioGr

payload plugin ai

by AlessioGr
AI search & embeddings
v?
alessiogr/payload#production-with-custom
MIT

Overview

Summary generated from the README

Adds an embeddings generator to Payload collections. A field opts in through a custom property, and embeddings are created each time the document is saved. The vectors can be searched with MongoDB Atlas search indexes. It currently requires a custom fork of Payload and may break between updates.

Features

  • Generates embeddings for chosen fields every time a document is saved
  • Supports OpenAI and NLP Cloud as embedding providers
  • Opt-in per field through a custom property helper
  • Optionally shows generated embeddings in the admin UI
  • Vectors can be queried with MongoDB Atlas knnVector search indexes

Use cases

  • Add semantic search over text fields in a Payload site backed by MongoDB
  • Store vector embeddings of content for similarity lookups

From the author

AI in payload

Installation

npm i payload-plugin-ai

15

Stars

0

Forks

0

Open Issues

3 years ago

Last Updated

25

Weekly Downloads

v1.1.0

npm Version

401.2 KB

Unpacked Size

3

Dependencies

GitHub stars

150 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 202615
Dec 4, 202615
Dec 3, 202615
Dec 2, 202615
Dec 1, 202615
Nov 30, 202615
Nov 29, 202615
Nov 28, 202615
Nov 27, 202615
Nov 26, 202615
Nov 25, 202615
Nov 24, 202615
Nov 23, 202615
Nov 22, 202615
Nov 21, 202615
Nov 20, 202615
Nov 19, 202615
Nov 18, 202615
Nov 17, 202615
Nov 16, 202615
Nov 15, 202615
Nov 14, 202615
Nov 13, 202615
Nov 12, 202615
Nov 11, 202615
Nov 10, 202615
Nov 9, 202615
Nov 8, 202615
Nov 7, 202615
Nov 6, 202615
Nov 5, 202615
Nov 4, 202615
Nov 3, 202615
Nov 2, 202615
Nov 1, 202615
Oct 31, 202615
Oct 30, 202615
Oct 29, 202615
Oct 28, 202615
Oct 27, 202615
Oct 26, 202615
Oct 25, 202615
Oct 24, 202615
Oct 23, 202615
Oct 22, 202615
Oct 21, 202615
Oct 20, 202615
Oct 19, 202615
Oct 18, 202615
Oct 17, 202615
Oct 16, 202615
Oct 15, 202615
Oct 14, 202615
Oct 13, 202615
Oct 12, 202615
Oct 11, 202615
Oct 10, 202615
Oct 9, 202615
Oct 8, 202615
Oct 7, 202615
Oct 6, 202615
Oct 5, 202615
Oct 4, 202615
Oct 3, 202615
Oct 2, 202615
Oct 1, 202615
Sep 30, 202615
Sep 29, 202615
Sep 28, 202615
Sep 27, 202615
Sep 26, 202615
Sep 25, 202615
Sep 24, 202615
Sep 23, 202615
Sep 22, 202615
Sep 21, 202615
Sep 20, 202615
Sep 19, 202615
Sep 18, 202615
Sep 17, 202615
Sep 16, 202615
Sep 15, 202615
Sep 14, 202615
Sep 13, 202615
Sep 12, 202615
Sep 11, 202615
Sep 10, 202615
Sep 9, 202615
Sep 8, 202615
Sep 7, 202615
Sep 6, 202615
npm weekly downloads

30+20 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202630
Dec 4, 202623
Dec 3, 202622
Dec 2, 202621
Dec 1, 202624
Nov 30, 202623
Nov 29, 202631
Nov 28, 202622
Nov 27, 202623
Nov 26, 202626
Nov 25, 202624
Nov 24, 202620
Nov 23, 202619
Nov 22, 202612
Nov 21, 202612
Nov 20, 202610
Nov 19, 20269
Nov 18, 20269
Nov 17, 20268
Nov 16, 20268
Nov 15, 20266
Nov 14, 20269
Nov 13, 202611
Nov 12, 202614
Nov 11, 202615
Nov 10, 202616
Nov 9, 202615
Nov 8, 202617
Nov 7, 202614
Nov 6, 202612
Nov 5, 202613
Nov 4, 202613
Nov 3, 202614
Nov 2, 202615
Nov 1, 202615
Oct 31, 202621
Oct 30, 202631
Oct 29, 202625
Oct 28, 202624
Oct 27, 202625
Oct 26, 202626
Oct 25, 202624
Oct 24, 202619
Oct 23, 20268
Oct 22, 20269
Oct 21, 20269
Oct 20, 20267
Oct 19, 20265
Oct 18, 20265
Oct 17, 20267
Oct 16, 20267
Oct 15, 20267
Oct 14, 20268
Oct 13, 20267
Oct 12, 202610
Oct 11, 202623
Oct 10, 202625
Oct 9, 202626
Oct 8, 202628
Oct 7, 202627
Oct 6, 202627
Oct 5, 202623
Oct 4, 202613
Oct 3, 20269
Oct 2, 202612
Oct 1, 202611
Sep 30, 202611
Sep 29, 202615
Sep 28, 202617
Sep 27, 202616
Sep 26, 202619
Sep 25, 202616
Sep 24, 202614
Sep 23, 202614
Sep 22, 202613
Sep 21, 202611
Sep 20, 20269
Sep 19, 20266
Sep 18, 20265
Sep 17, 20267
Sep 16, 20269
Sep 15, 20268
Sep 14, 202610
Sep 13, 202610
Sep 12, 20269
Sep 11, 20269
Sep 10, 20268
Sep 9, 20267
Sep 8, 20266
Sep 7, 20268
Sep 6, 202610

Each point is npm's rolling 7-day download count.

Health Score

39/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/623612490-root.svg)](https://payloaddirectory.dev/plugins/623612490-root)
HTML
<a href="https://payloaddirectory.dev/plugins/623612490-root"><img src="https://payloaddirectory.dev/badge/623612490-root.svg" alt="Payload Directory"></a>
Updated Apr 18, 2023Created Apr 4, 2023Published Apr 18, 2023

README

Payload AI plugin

npm version

ATTENTION: This plugin currently requires a custom fork of payload to work (replace payload with yarn add alessiogr/payload#production-with-custom). This is because this plugins depends on two PRs which haven't been merged into payload yet:

In this repository I will add a bunch of AI stuff! Currently, it can just generate embeddings for fields using the OpenAI API. Expect things to break with updates without notice.

Installation

yarn add payload-plugin-ai

Add this to your payload.config.ts:

import { ai } from 'payload-plugin-ai';

...

plugins: [
    ai({
      OPENAI_SECRET: process.env.OPENAI_SECRET,
      NLPCLOUD_API_KEY: process.env.NLP_CLOUD_API_KEY,
      embeddings: {
        provider: "nlpcloud", // Nlpcloud is recommended
      },
    }),
]

Embeddings

Embeddings generated in the Admin UI

To enable embeddings on a field, simply add this property to the field:

import { genEmbeddings } from 'payload-plugin-ai';

...

yourField: {
  ...
  custom: {
        ...genEmbeddings({ visible: true }),
  },
}

Now, every time you save the collection, embeddings for that field will be generated.

Search through embeddings

You can use MongoDB atlas search to search through embeddings. In MongoDB Atlas, create a search index which looks like this:

{
  "mappings": {
    "fields": {
      "textArea_embeddings": [
        {
          "dimensions": 768,
          "similarity": "euclidean",
          "type": "knnVector"
        }
      ]
    }
  }
}

Replace textArea_embeddings with the name of the embeddings field generated by this plugins.

Once the index is created, you can search through your documents using something like mongoose. There's an example in the payload.config.ts in the demo folder (make sure you adjust the index name and the path).

Other

Project structure inspired by payload-plugin-cloud-storage and pcms-backpop

Similar plugins