Package Exports
- gatsby-plugin-recommend-article
- gatsby-plugin-recommend-article/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gatsby-plugin-recommend-article) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
gatsby-plugin-recommend-article
Gatsby plugin to recommend articles based on OpenAI embeddings API and Qdrant vector search.
View the demo site on GitHub Pages
View the demo repository
Install
with npm
npm install gatsby-plugin-recommend-articlewith yarn
yarn add gatsby-plugin-recommend-articlewith pnpm
pnpm add gatsby-plugin-recommend-articlewith bun
bun add gatsby-plugin-recommend-articleQuick start
- Add the plugin to your
gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-recommend-article`,
options: {
qdrant: {
url: "<your-qdrant-url>",
},
openai: {
apiKey: "<your-openai>",
},
limit: 3,
toPayload: ({ node }) => {
return {
title: node.frontmatter.title,
content: node.excerpt,
tags: node.frontmatter.tags,
};
},
},
},
],
};- Query for recommended articles
query {
allMarkdownRemark(filter: { id: { eq: "xxxx" } }) {
nodes {
id
excerpt
recommends {
id
excerpt
}
}
}
}{
"data": {
"allMarkdownRemark": {
"nodes": [
{
"id": "xxxx",
"excerpt": "...",
"recommends": [
{
"id": "yyyy",
"excerpt": "..."
},
{
"id": "zzzz",
"excerpt": "..."
},
...
]
},
]
}
}
}Options
| Name | Type | Description | Default | Required |
|---|---|---|---|---|
| qdrant | object | Configuration for Qdrant. | - | ✅ |
| openai | object | Configuration for OpenAI. | - | ❌ |
| limit | number | Maximum number of recommended articles. | 5 | ❌ |
| nodeType | string | Type of node to add recommends field. Also, the type of recommends is an array of the specified type. |
"MarkdownRemark" | ❌ |
| toPayload | function | Function to convert node to payload. payload is only used to generate vector. | (node) => JSON.stringify({ body: node.excerpt ?? "" }) |
❌ |
qdrant
| Name | Type | Description | Default | Required |
|---|---|---|---|---|
| url | string | URL of the Qdrant server | - | ✅ |
| apiKey | string | API key for authenticating with Qdrant | - | ❌ |
| https | boolean | Whether to use HTTPS | false | ❌ |
| headers | object | Additional headers for requests | {} |
❌ |
| onDisk | boolean | Whether to use on-disk storage | false | ❌ |
| collectionName | string | Name of the Qdrant collection to use | "articles" | ❌ |
openai
| Name | Type | Description | Default | Required |
|---|---|---|---|---|
| baseURL | string | base URL for the OpenAI API | - | ❌ |
| apiKey | string | API key for authenticating with OpenAI | - | ❌ |
| organization | string | ID of the OpenAI organization | - | ❌ |
| project | string | ID of the OpenAI project | - | ❌ |
| embeddingModel | string | Model used for generating embeddings | "text-embedding-3-small" | ❌ |
| embeddingSize | number | Size of the embedding vector | 1536 | ❌ |
Contributing
Feel free to open a PR or an Issue.
However, you must promise to follow our Code of Conduct.
See here for more details on contributing.
License
gatsby-plugin-recommend-article released under the MIT License