Turning a WordPress database into an AI knowledge base is not a matter of sending every row to a language model. A production implementation needs a controlled extraction, normalization, indexing, and retrieval pipeline that preserves WooCommerce context, permissions, content freshness, and answer traceability.
What the knowledge base should contain
For a WooCommerce site, useful knowledge is distributed across several WordPress data structures:
- Content: posts, pages, products, product variations, documentation, FAQs, and custom post types.
- Metadata: product attributes, SKUs, specifications, custom fields, and editorial metadata stored in
wp_postmeta. - Taxonomies: product categories, tags, brands, shipping classes, and custom taxonomies.
- Commerce data: product prices, stock status, dimensions, downloadable files, and selected order or customer-support fields.
- Relationships: parent products, variations, cross-sells, upsells, related posts, and taxonomy assignments.
The database is the source of record, but it is usually not the best format for retrieval. An AI knowledge base should contain clean, human-readable documents with explicit identifiers, searchable text, structured fields, timestamps, and access-control metadata.
Use the database as a source, not as the prompt
Directly concatenating database rows into an AI prompt creates several problems. WordPress content is split between normalized tables and serialized metadata. The same product information may appear in the post content, excerpt, custom fields, taxonomy terms, and variation records. Raw rows also contain implementation details that are irrelevant to an answer and may expose private information.
A safer architecture has four stages:
- Extract: read published and permitted WordPress data.
- Normalize: combine related rows into canonical documents.
- Index: send searchable fields and document chunks to WPSOLR and its configured search backend.
- Retrieve: find relevant documents at query time and provide only those documents to the AI workflow.
Extract content through WordPress-aware interfaces
For a one-time migration, a read-only database export may be appropriate. For an operational knowledge base, prefer WordPress APIs, WP-CLI commands, and lifecycle hooks where possible. WordPress-aware extraction correctly handles revisions, post status, language plugins, capabilities, product relationships, and content filters.
A database query can help identify candidates for reindexing, but it should not be the only source of business logic. For example, a query against wp_posts can locate recently changed products, while WooCommerce APIs or product objects should provide the final product representation.
SELECT ID, post_modified_gmt FROM wp_posts WHERE post_type = 'product' AND post_status = 'publish' AND post_modified_gmt > '2025-01-01 00:00:00';
In production, replace the table prefix with the installation-specific prefix and use parameterized queries. Never assume that wp_ is the correct prefix, and never expose database credentials or private tables to an AI service.
Build canonical documents
A canonical document represents one retrievable business object. A product document might include the product ID, SKU, title, description, attributes, categories, availability, and a stable URL. It should not reproduce every database column.
{
'id': 'product:4821',
'type': 'product',
'title': 'Insulated Stainless Steel Bottle',
'url': 'https://example.com/product/insulated-stainless-steel-bottle/',
'sku': 'BOT-750-BLK',
'content': 'A 750 ml insulated stainless steel bottle with a leak-resistant lid.',
'attributes': {
'capacity': '750 ml',
'color': 'Black'
},
'taxonomies': ['Drinkware', 'Outdoor Products'],
'modified_gmt': '2025-01-15 13:42:00',
'visibility': 'public'
}
The example uses a conceptual representation. Actual JSON payloads require double-quoted property names. The important design decision is separating searchable content from metadata used for filtering, ranking, authorization, and synchronization.
Handle WooCommerce data carefully
Product information is generally suitable for a public knowledge base when the product is published and visible in the catalog. Customer records, billing addresses, shipping addresses, order notes, refunds, and payment information require a different access model and should not be indexed into a public assistant.
If an internal support assistant needs order information, index it in a restricted collection or retrieve it at request time after verifying the authenticated user and order permissions. A customer-facing assistant should normally receive only a narrowly scoped order status result, not the complete order record.
Variations need deliberate treatment. Indexing every variation as an unrelated document can produce repetitive results, while indexing only the parent product can hide important differences in size, color, price, or stock. A practical approach is to index a parent product document with a structured variation summary and optionally create variation documents when customers search for variation-specific attributes.
Normalize before indexing with WPSOLR
WPSOLR can serve as the search and retrieval layer between WordPress content and an AI workflow. The exact configuration depends on the selected Solr or Elasticsearch-compatible backend, but the indexing principles remain consistent:
- Index the title, rendered content, excerpt, SKU, attributes, and taxonomy labels as separate fields where useful.
- Keep identifiers such as post IDs, product IDs, SKUs, language codes, and site IDs as exact-match fields.
- Store publication status and visibility so unpublished or restricted content cannot be returned accidentally.
- Store the canonical URL and source timestamp for citations and freshness checks.
- Use analyzers appropriate for the languages and product terminology used by the store.
Do not index raw serialized values from wp_postmeta as if they were readable text. Deserialize and map known fields into a stable schema. For custom fields, define a field allowlist rather than exporting every value by default.
Choose chunk boundaries based on user questions
Large pages should be split into chunks, but arbitrary character limits are rarely sufficient. Split documentation at headings, product sections, troubleshooting steps, or policy boundaries. Each chunk should retain enough context to stand alone, including the document title, product name, section heading, and canonical URL.
For example, a returns policy can be divided into eligibility, time limits, exclusions, and process sections. A retrieval result containing only the sentence Items must be returned within 30 days is less useful than a chunk that also identifies which products and conditions the rule applies to.
Use stable chunk IDs such as page:913:returns-policy:eligibility. Stable IDs make updates and deletions deterministic and prevent stale chunks from remaining in the index after an editor changes a page.
Combine lexical and semantic retrieval
WooCommerce searches often contain exact identifiers such as SKUs, model numbers, part codes, and coupon names. They also contain semantic questions such as Which bottle is suitable for keeping drinks cold during a hike? Exact-match and lexical search are strong for the first type, while semantic retrieval can help with the second.
A robust AI search layer uses hybrid retrieval:
- Run keyword or fielded search for exact terms, SKUs, brands, and filters.
- Run semantic retrieval for natural-language intent and related phrasing.
- Merge and rerank the results using business rules such as publication status, stock availability, language, and product visibility.
- Pass only the highest-quality, authorized results to the generation step.
WPSOLR can provide the searchable index and query controls, while the AI application remains responsible for prompt construction, response policy, citations, and permission checks.
Keep the index synchronized
A knowledge base becomes unreliable when it contains yesterday’s price, an unpublished product, or an outdated returns policy. Use event-driven updates for normal operation and scheduled reconciliation for recovery.
- Queue an update when a relevant post or product is created, edited, published, unpublished, or deleted.
- Reindex related documents when a taxonomy term, global policy, or shared attribute changes.
- Use a background worker instead of blocking the WordPress editor request.
- Record the source version, modification time, indexing status, and error message.
- Run a periodic full or incremental comparison to detect missed webhook or queue events.
For high-volume stores, process changes in batches and make the operation idempotent. Reprocessing the same product should replace its existing document rather than create duplicates.
Validate retrieval before adding AI generation
Test the knowledge base independently of the language model. Create a query set containing product searches, policy questions, SKU lookups, multilingual queries, and questions about unavailable products. Measure whether the correct document appears in the top results and whether restricted documents are excluded.
Useful checks include:
- Can a published product be found by its SKU and by its natural-language description?
- Does an unpublished product disappear after its status changes?
- Are variation attributes represented accurately?
- Does a customer-support query exclude private customer data?
- Does every answerable result contain a current URL and source timestamp?
Only after retrieval is dependable should the AI layer summarize results or formulate an answer. This separation makes failures easier to diagnose: an incorrect answer may result from missing source content, poor retrieval, an authorization error, or an unsupported generation step.