Embeddings and sync

Before the chatbot can answer from your content, the content has to be in a vector database. KimaAI splits each page, post or PDF into passages, turns every passage into an embedding (numbers that describe its meaning) with an AI model, and stores them in your Pinecone or Qdrant database. This page connects the database, syncs your content to it and keeps it in sync when you publish and edit.

Set it up

You need an AI environment with an embedding model, such as OpenAI’s text-embedding-3-small (AI environments), and a Pinecone or Qdrant account (Pinecone, Qdrant).

  1. In the KimaAI admin, go to Connections and open the Vector databases tab.
  2. Select Add embedding environment.
  3. Give it an Environment name, choose the WordPress environment it is for, and choose the Vector database provider.
  4. Enter the API key and the Index host your provider gives you. A Qdrant server of your own that runs without a key needs only its address in Index host.
  5. Open AI environment and choose the AI environment and the AI model that make the embeddings.
  6. Select Test now under Connection test, then Add.
  7. Go to Knowledge → Sources and sync. The Sync tab lists your content per source.
  8. Choose a Source, tick the items to sync, and select Sync.
  9. In the dialog, select Sync selected (or Force re-sync selected for items that are synced already) and wait until every item is done.

The vector databases on Connections:

The Vector databases tab of Connections with the demo site's Pinecone index
  1. Add embedding environment opens the form for a new one, titled Add embedding environment.
  2. A vector database, with its WordPress environment under its name. Select it to change it.
  3. Status shows the result of the last connection test: Connected, Needs attention, Not tested, or Not set up without an API key (a Qdrant database counts as set up with its Index host alone).

The Sync tab of Knowledge → Sources and sync:

Knowledge → Sources and sync, Sync tab, with the demo site's pages
  1. The vector database the page works with, and Manage on Connections.
  2. Source: the post type, or the PDF files, to list.
  3. Ticks every item on the page.
  4. Embedding shows whether an item is Synced or Not synced. The menu at the end of a row syncs or deletes that item alone.

From then on, new and edited content syncs by itself, as set on the Settings tab:

The On first publish section on the Settings tab of Knowledge → Sources and sync
  1. Auto-embed on first publish syncs a post when it is published.
  2. Restrict to post types limits the automatic syncs to some post types.

Then switch the chatbot on to answer from it: see Knowledge base.

Settings

Vector database

SettingWhat it does
Environment nameA name for this vector database in KimaAI.
WordPress environmentThe WordPress environment this database is used in: production, staging, development or local. On a site running in another, it is not used.
Vector database providerPinecone or Qdrant.
API keyThe API key of your vector database. Pinecone needs one; a Qdrant server of your own may run without.
Index hostThe host of your Pinecone index, such as example-1234.svc.us-west1.pinecone.io, or the address of your Qdrant server.
CollectionQdrant only: the collection that holds this site’s content; it must exist in Qdrant. Empty, KimaAI uses one named after your site’s domain.
NamespacePinecone only: the namespace that holds this site’s content in the index. Empty, KimaAI uses one named after your site’s domain.

AI environment

SettingWhat it does
AI environmentThe AI environment whose provider makes the embeddings.
AI modelThe embedding model. Its dimension must match the collection or index: 1536 for text-embedding-3-small.

Score

SettingWhat it does
Min scoreLeaves out the passages less similar to a question than this, in percent: 35 is a similarity of 0.35, and 0, the default, leaves nothing out. It applies to the chatbot’s searches, the Query tab and wp kimaai vectors query. A Minimum similarity score above 0 in the knowledge base replaces it for the chatbot.
Max resultsHow many passages wp kimaai vectors query returns when you do not pass --top, from 1 to 100; the default is 10. The chatbot uses the Max results per question of the knowledge base instead, the Query tab its Top results.

On first publish

SettingWhat it does
Auto-embed on first publishSyncs a post in the background the first time it is published, also when a scheduled post goes live or a plugin publishes it.
Restrict to post typesLimits the automatic syncs, on first publish and on update, to the post types you tick. With none ticked, every post type KimaAI can sync is synced.

On update

SettingWhat it does
Auto re-embed on updateSyncs a post again in the background when it is updated. Posts that are not synced yet are left as they are.

Index maintenance

SettingWhat it does
Weekly reconcileOnce a week, removes the passages of deleted and unpublished posts from the database, and logs the posts whose passages are out of date.

Content template

SettingWhat it does
Post typeThe slug of the post type the template applies to, such as product or event.
TemplateOne statement per line with tokens, such as Article number: {meta:_sku}. A line whose tokens are all empty for a post is left out for it.
EnabledA template that is switched off is kept but not applied.

How it works

  • What can be synced. Every public post type, such as posts, pages and WooCommerce products, and PDF files from the media library.
  • Passages. KimaAI splits the text by headings and paragraphs into passages of about 500 tokens, each overlapping the one before by about 50, and starts each with the page’s title and heading. With each passage it stores the post’s title, address, type, language and heading.
  • Syncing by hand. A sync from the Sync tab always makes the embeddings again, also for synced items (Force re-sync). Up to 10 items sync while the dialog shows their progress; more are queued in the background.
  • Syncing by itself. Published and updated posts are synced in the background, with Action Scheduler, to the first vector database for the WordPress environment the site runs in. A post that is unpublished, trashed, deleted or given a password is removed from the database at once, whatever the settings.
  • Content templates. On Knowledge → Content templates, a template adds structured data that is not in the text, such as custom fields and taxonomies, to every post of a post type. The tokens are {title}, {permalink}, {meta:key}, {tax:taxonomy} and {acf:field}; the filled-in lines are added at the end of the post’s text before it is split. A change applies at the next sync of the post type.
  • The other tabs. Query shows which passages a question finds, with their scores. Collections lists the collections or indexes in the database and creates new ones. Health checks the database, the embedding model, the collection, the synced content, failed items, changed content and the last sync, with the fix for anything that fails.
  • Test now checks the connection, and then the place your content goes: the index at the Index host (Pinecone) or the Collection you entered (Qdrant) must answer or exist, or the test fails. Without one, a successful test creates the collection or index named after your site if it does not exist yet, with dimension 1536.
  • WP-CLI has the same tools: wp kimaai vectors sync, wp kimaai vectors freshness, wp kimaai vectors reconcile and more (WP-CLI commands).

Troubleshooting

  • Sync is switched off on the Sync tab. A check on the Health tab fails: open it and follow its fix.
  • The test fails. Check the API key and the index host or server address with your provider, and that the AI environment has a valid key. For a Qdrant Collection of your own, check that it exists.
  • A post is missing in the answers. Find it on the Sync tab: if it shows Not synced, sync it. Password-protected posts are never synced.
  • The vector database is not offered on a staging site. Each vector database belongs to one WordPress environment: add one for staging, or change its environment.

What are your feelings