Skip to content

Create a Searchable FAQ From a Small Document Folder

Three small Markdown files are enough to build a searchable FAQ when each has a stable source ID, a precise retrieval query, and a canonical source link. This example uses the OpenAI API’s File Search with a vector store: a searchable index of uploaded files. It creates three invented help-center entries, checks which files match two queries, and asks for a grounded answer with links copied from the source metadata.

Prerequisites and intended result

Install the current OpenAI Python SDK with pip install openai, set OPENAI_API_KEY in your environment, and save the three files below in a sources/ folder. The API call uses a model available to your account; the example uses gpt-6-astra, as shown in the current File Search guide. Markdown files are supported, and text files must use UTF-8, UTF-16, or ASCII encoding. File Search documentation

.md is a supported File Search format with MIME type text/markdown; text MIME inputs must use UTF-8, UTF-16, or ASCII encoding.

Each source has an ID that stays the same when its content is revised, a unique heading anchor, and a canonical relative URL. The ID and URL live in the document itself, so the answer can point readers to the exact local entry rather than relying on a search-result position that might change.

Create the three fixtures and run retrieval

These fixtures are invented sample data. They describe a fictional company’s support policies; replace them with your own material before using the workflow for real answers.

Example input: Save these as sources/SRC-101.md, sources/SRC-102.md, and sources/SRC-103.md.

<!-- sources/SRC-101.md -->
SOURCE_ID: SRC-101
SOURCE_URL: ./sources/SRC-101.md#refund-window

# Refunds

## Refund window {#refund-window}
Customers may request a refund within 30 calendar days after purchase.
To request one, email support@example.test with the order number.
<!-- sources/SRC-102.md -->
SOURCE_ID: SRC-102
SOURCE_URL: ./sources/SRC-102.md#cancel-renewal

# Subscriptions

## Cancel renewal {#cancel-renewal}
Customers can turn off renewal from Account > Billing > Manage plan.
Cancellation stops the next renewal; access remains active until the current paid period ends.
<!-- sources/SRC-103.md -->
SOURCE_ID: SRC-103
SOURCE_URL: ./sources/SRC-103.md#support-hours

# Support

## Support hours {#support-hours}
Support replies Monday through Friday, 09:00–17:00 UTC.
The team is closed on public holidays observed in its service region.

Run this complete script from the folder containing sources/. It creates a vector store, uploads each file, waits for processing, runs two retrieval queries, then asks the model to answer one question. upload_and_poll waits for indexing to finish; the explicit search calls let you inspect matches before relying on the generated FAQ entry. Retrieval documentation

from pathlib import Path

from openai import OpenAI

client = OpenAI()
source_paths = [
    Path("sources/SRC-101.md"),
    Path("sources/SRC-102.md"),
    Path("sources/SRC-103.md"),
]

store = client.vector_stores.create(name="Support FAQ example")

for path in source_paths:
    with path.open("rb") as source_file:
        client.vector_stores.files.upload_and_poll(
            vector_store_id=store.id,
            file=source_file,
        )

queries = [
    "How long after purchase can someone request a refund, and how?",
    "How does a customer stop renewal, and when does access end?",
]

for query in queries:
    results = client.vector_stores.search(
        vector_store_id=store.id,
        query=query,
    )
    print(f"\nQUERY: {query}")
    for result in results.data:
        print(f"{result.filename}: {result.content}")

prompt = """Answer only from the retrieved files.
If the files do not support an answer, say what is missing.
Do not combine refund eligibility with subscription cancellation.
For every factual answer, include the exact SOURCE_ID and copy SOURCE_URL
from the source text as a Markdown link. Do not invent or rewrite link targets.
Keep the answer to 2–4 sentences."""

response = client.responses.create(
    model="gpt-6-astra",
    input="Can I cancel renewal and get a refund after 30 days?",
    tools=[{"type": "file_search", "vector_store_ids": [store.id]}],
    include=["file_search_call.results"],
)
print("\nANSWER:")
print(response.output_text)

The search queries are deliberately phrased as reader questions, including the action and the condition likely to distinguish the relevant source. File Search may return relevant passages and citations, but your local link format comes from SOURCE_URL; inspect the returned filenames and excerpts to confirm that those IDs and links belong to the retrieved evidence.

Check acceptance criteria and handle misses

Expected output: For the first query, expect SRC-101.md with the 30-day refund window and email instruction; for the second, expect SRC-102.md with the billing path and end-of-period access detail. These are illustrative matches, not actual test results. An illustrative answer to the final question is:

You can stop renewal at Account > Billing > Manage plan, and access continues until the paid period ends ([SRC-102](./sources/SRC-102.md#cancel-renewal)). The refund rule applies only to requests made within 30 calendar days after purchase; the files do not establish eligibility after that period ([SRC-101](./sources/SRC-101.md#refund-window)).

Verify the result: Check that both query outputs include the expected filename and supporting text; confirm each answer link’s target exactly matches that file’s SOURCE_URL; and verify that “after 30 days” is described as unsupported rather than approved. The response can include file citation annotations, while include=["file_search_call.results"] makes the retrieved passages available to inspect. File Search documentation

File Search results can expose a filename, file_id, and text content, while the response can include file citation annotations; these are useful for checking sources but do not themselves define a local Markdown URL.

If a query returns no match or the wrong file, first check that all three uploads completed and that the printed filename is the expected one. Then search with a concrete phrase from the source, such as “refund within 30 calendar days after purchase.” If the source text or anchor changed, update its SOURCE_URL and re-upload the revised file so the answer does not preserve a stale link.

This workflow suits a small, maintained folder of concise text policies. It is unsuitable when readers need guaranteed answers from frequently changing records, complex access controls, or high-stakes decisions that require a human review process. Retrieval finds relevant text; it does not prove that the source is current or that an answer is correct.

Frequently Asked Questions (FAQ)

Q1) Why use source IDs if the files already have names?

Filenames can change during editing or when files are reorganized, so use a stable ID such as SRC-102 for references across drafts. Keep the ID in the file and make it unique within the folder. If you retire a source, do not reuse its ID for unrelated content.

Q2) What if the answer needs evidence from two files?

Ask one question that explicitly names both issues, then check that retrieval returned passages from each relevant source. The refund and renewal rules in this example are separate policies, so a combined answer should link each claim to its own source. If one source is missing, say the evidence is incomplete instead of inferring a connection.

Q3) Can I use this exact workflow in a ChatGPT Project?

Projects can hold files and project instructions, but availability and file limits vary by plan and workspace settings. The official upload format list for ChatGPT conversations includes TXT, DOCX, and PDF, not Markdown, so convert the fixtures to a supported format or use the API workflow above. In either case, preserve source IDs and verify any generated links before publishing. Projects in ChatGPT, file upload guidance

Leave a comment