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
npm install gatsby-plugin-recommend-article
yarn add gatsby-plugin-recommend-article
pnpm add gatsby-plugin-recommend-article
bun add gatsby-plugin-recommend-article
- 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": "..."
},
...
]
},
]
}
}
}
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 ?? "" }) |
❌ |
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" | ❌ |
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 | ❌ |
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.
gatsby-plugin-recommend-article released under the MIT License