Skip to main content

kb-bot.core

The core library of kb-bot. This handles indexing of content, and chatting with the bot.

Getting Started

pip install kb-bot.core

Preparing the KB

import os
from kb_bot import KBBot
from kb_bot.scraper import WebScraper
from kb_bot.db import TiDBProvider
from kb_bot.chunkers import SemanticChunker
from kb_bot.embedding import OpenAIEmbedClient
from kb_bot.llm import OpenAI

# Configure env variables TIDB_DATABASE, TIDB_USERNAME, TIDB_PASSWORD, TIDB_HOST, TIDB_PORT
tidb = TiDBProvider()
tidb.connect()

embed_client = OpenAIEmbedClient(
    api_key=os.environ.get('OPENAI_API_KEY')
)

scraper = WebScraper(
    urls=["https://www.pingcap.com/blog/"],
    follow_links=True,
    restrict_navigation_css=".tmpl-archive.tmpl-archive-blog",
    restrict_css=".tmpl-single-post__content",
    ignore_css=".tmpl-archive-sidebar",
    chunker=SemanticChunker(
        embedding_client=embed_client
    ),
    db_provider=tidb,
    group="<user user id or project id according to your need>",
    embedding_client=embed_client
)

scraper.crawl()

Chat with the bot

bot = KBBot(
    db_provider=tidb,
    embedding_client=embed_client,
    group="new-user-id",
    llm_client=OpenAI(
        api_key=os.environ.get('OPENAI_API_KEY')
    ),
    history=[],
    tasks_prompt="<Additional instructions to bot>"
)

response = bot.chat(message="what are the benefits of vector search ?")
print(response)

TODO

  • Add support for multiple llm(s)
  • Implement Agentic Chunker
  • Add test cases

Metadata

Release files for kb-bot.core 0.1.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kb-bot.core 0.1.21
File Size Uploaded
kb_bot_core-0.1.21.tar.gz 10.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kb-bot.core 0.1.21
File Interpreter ABI Platform
kb_bot.core-0.1.21-py3-none-any.whl Python 3 none any Details

Total release size: 21.0 kB

Release files / kb_bot_core-0.1.21.tar.gz

Download URL kb_bot_core-0.1.21.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a95bef72955bd80dae80644ea299403fd1e1831de5d5574061f48c1956e58718
BLAKE2b-256 checksum
How to use checksums
3db21080c8dd98bd693b43c5fd4a47df37bedda825f9b6a04e3038040b42a08b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / kb_bot.core-0.1.21-py3-none-any.whl

Download URL kb_bot.core-0.1.21-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b104bd82d9c15bf4ded478d2a49582a4d39dfc4f0080893aa7614b466962c17e
BLAKE2b-256 checksum
How to use checksums
1151571150be8b12b59bfa2bfd10e178b886ee3e065c3507be86f30b38142caa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.1.21 This release

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

1 release file

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page