Question-Answer Store
Like key-value, but with questions and answers.
A Python package for managing and querying a Question-Answer Knowledge Base using vector embeddings and tree structures.
Features
- Store and retrieve question-answer pairs
- Generate question rewordings for improved retrieval
- Metadata support for filtering and additional information
- Vector-based similarity search for efficient querying
- Persistent storage using ChromaDB
- Tree structure for organizing questions hierarchically
- Automatic generation of question-answer pairs from text
- Priority-based question suggestion system
- Visualization of the question tree
Installation
You can install qa-store using pip:
pip install qa-store
Usage
Here's a quick example of how to use qa-store:
from qa_store import QuestionAnswerSystem
# Initialize the Question Answer System
qas = QuestionAnswerSystem("qa_system.db", "qa_collection")
# Add a question to the tree
question_id = qas.add_question("What is the capital of France?")
# Answer the question
qas.answer_question(question_id, "Paris")
# Query the Knowledge Base
results = qas.query("What's the capital city of France?")
print(results[0]["answer"]) # Output: Paris
# Get unanswered questions
unanswered = qas.get_unanswered_questions()
# Get the next suggested question
next_question = qas.suggest_next_question()
Advanced Usage Example
This example showcases the use of the QuestionAnswerSystem, including adding questions, answering them, and querying the knowledge base:
from qa_store import QuestionAnswerSystem
# Initialize the Question Answer System
qas = QuestionAnswerSystem("qa_system.db", "qa_collection")
# Add a root question
root_id = qas.add_question("What are the main topics in computer science?")
# Add child questions
qas.add_question("What is machine learning?", parent_id=root_id)
qas.add_question("What are data structures?", parent_id=root_id)
# Answer some questions
qas.answer_question(root_id, "The main topics in computer science include algorithms, data structures, artificial intelligence, and software engineering.")
# Query the Knowledge Base
results = qas.query("What are the fundamental areas of computer science?", num_rewordings=2)
print("\nQuery results:")
for result in results:
print(f"Question: {result['question']}")
print(f"Answer: {result['answer']}")
print(f"Similarity: {result['similarity']:.2f}")
print(f"Metadata: {result['metadata']}")
print()
# Get the next suggested question
next_question = qas.suggest_next_question()
if next_question:
print(f"Suggested next question: {next_question['question']}")
Advanced Features
Generating QA Pairs from Text
You can automatically generate question-answer pairs from a given text:
from qa_store import QuestionAnswerKB
kb = QuestionAnswerKB()
text = """
Machine learning is a subset of artificial intelligence that focuses on
the development of algorithms and statistical models that enable
computer systems to improve their performance on a specific task through
experience.
"""
qa_pairs = kb.generate_qa_pairs(text)
for pair in qa_pairs:
kb.add_qa(pair['q'], pair['a'])
Visualizing the Question Tree
You can visualize the question tree structure:
from qa_store import QuestionAnswerTree
tree = QuestionAnswerTree("qa_tree.db")
tree.visualize("question_tree")
This will generate a PNG image of the question tree.
For more detailed usage instructions, please refer to the documentation.
Requirements
- Python 3.7+
- Dependencies listed in
requirements.txt
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
Donald Thompson - @dt_public - witt3rd@witt3rd.com
Project Link: https://github.com/witt3rd/qa-store
Metadata
Release files for qa-store 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qa_store-0.2.1.tar.gz | 16.5 kB | Without provenance | Details for qa_store-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qa_store-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for qa_store-0.2.1-py3-none-any.whl |
Total release size: 30.0 kB
Release files / qa_store-0.2.1.tar.gz
| Download URL | qa_store-0.2.1.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f35faf9672145a2e4d1cc3011e359ad13ec422b8a4445549ad2cee060904332
|
|
BLAKE2b-256 checksum How to use checksums |
7840e4306a46998eaa6358defb21859cf41513087a3eb8d2b552770066f40bd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / qa_store-0.2.1-py3-none-any.whl
| Download URL | qa_store-0.2.1-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
56c398b4d8726cc79734ea0dc4a47b478dba05edad00b8426a56e8fc7a29a0a0
|
|
BLAKE2b-256 checksum How to use checksums |
a8ba48ec3738d8f69338d6e7f6f3a0914b08d9ae70c5a004d9e506f830a9748f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Security for qa-store 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.