Download and extract the Python Demo package.
The package contains the scripts and configuration used to demonstrate collection management, document processing, inference, and related API operations.
The Python Demo provides a functional starting point for application development. Use the complete workflow to see collection creation, document processing, and AI inference working together, then explore individual scripts for specific collection and inference operations.
Make sure you have:
If you haven't configured API access, see Set up Knowledge Base API access.
Download and extract the Python Demo package.
The package contains the scripts and configuration used to demonstrate collection management, document processing, inference, and related API operations.
Create a virtual environment:
python3 -m venv venv
Activate the environment:
Install the dependencies:
pip install --upgrade pip
pip install -e .
Add the required API credentials and service configuration to config.yaml.
Change to the python subfolder before running the sample scripts.
The demo uses requests, pyyaml, and tqdm. Credentials are stored in config.yaml, and authentication tokens are managed automatically.
Do not commit config.yaml or generated .token files to source control.
Run:
python knowledgebase.py
To use a specific PDF:
python knowledgebase.py --document=<path-to-pdf>
The demo:
Upload and indexing are distinct parts of document ingestion. Indexing extracts the document content and makes it available to AI operations.
If you don't specify a PDF, the demo selects one from the package's documents directory. Document processing times out after five minutes if it doesn't reach a complete state.
The complete workflow creates a collection named demo-collection and uploads a PDF to it. The demo does not delete the collection or uploaded document when the workflow finishes.
After running the complete workflow, use individual scripts to explore specific API operations.
python collection.py --action create --name <collection-name>
Collection names can contain up to 255 characters.
python collection.py --action list
Choose whether to list collections created by you, shared by you, or shared by others when prompted.
python collection.py --action share --collection-id <collection-id>
Enter the email addresses that should receive read or write access when prompted.
python collection.py --action upload --collection-id <collection-id> --path=<path-to-file-or-directory>
The script can upload a single file or documents from a specified directory.
python collection.py --action get_documents --collection-id <collection-id>
python collection.py --action get_status --document-id <document-id>
The demo provides these operations as standalone examples that you can inspect and adapt independently of the complete workflow.
The inference examples require a collection ID and document ID. Use the collection scripts to identify them:
python collection.py --action list
python collection.py --action get_documents --collection-id <collection-id>
List your collections and documents, then run the Q&A example:
python collection.py --action list
python collection.py --action get_documents --collection-id <collection-id>
python inference.py --questionAnswer
Enter the collection ID, document ID, and question when prompted.
Identify the collection and document, then run the summarization example:
python collection.py --action list
python collection.py --action get_documents --collection-id <collection-id>
python inference.py --summarize
Enter the collection ID and document ID when prompted.
Identify the collection and document, then run the context-search example:
python collection.py --action list
python collection.py --action get_documents --collection-id <collection-id>
python inference.py --context-search
Enter the collection ID, document ID, and search text when prompted.
Identify the collection and document, then run the extraction example:
python collection.py --action list
python collection.py --action get_documents --collection-id <collection-id>
python inference.py --extract
Enter the collection ID, document ID, property name, extraction prompt, data type, and optional description when prompted.
The Python Demo provides working implementation patterns rather than complete API documentation.
Use Get started with the Knowledge Base API to understand the API resource model, document lifecycle, inference behavior, and response handling.
Use the Knowledge Base API reference when you need current endpoint paths, parameters, request and response schemas, and status information.
The demo writes detailed diagnostic information to:
logs/knowledgebase-demo.log
The log file records DEBUG-level information, while the console displays WARNING-level messages and above.
If an operation fails: