Skip to main content

Like a key-value store, but for questions and answers.

Project description

Question-Answer Store

Like key-value, but with questions and answers.

PyPI version GitHub license GitHub issues GitHub stars Twitter

A Python package for managing and querying a Question-Answer Knowledge Base using vector embeddings.

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

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 QuestionAnswerKB

# Initialize the Knowledge Base
kb = QuestionAnswerKB()

# Add a question-answer pair
kb.add_qa("What is the capital of France?", "Paris", metadata={"source": "Geography 101"})

# Query the Knowledge Base
results = kb.query("What's the capital city of France?")
print(results[0]["answer"])  # Output: Paris

# Update an answer
kb.update_answer("What is the capital of France?", "Paris (City of Light)")

# Query with metadata filter
results = kb.query("capital of France", metadata_filter={"source": "Geography 101"})

Advanced Usage Example

This example showcases the use of question rewordings for both adding QA pairs and querying the knowledge base:

from qa_store import QuestionAnswerKB

# Initialize the Knowledge Base
kb = QuestionAnswerKB()

# Add a question-answer pair with rewordings
original_question = "What is the best way to learn programming?"
answer = "The best way to learn programming is through consistent practice, working on real projects, and continuous learning."

added_questions = kb.add_qa(
    question=original_question,
    answer=answer,
    metadata={"topic": "education", "field": "computer science"},
    num_rewordings=3
)

print("Added questions:")
for q in added_questions:
    print(f"- {q}")

# Now let's query the Knowledge Base with a different phrasing
query_question = "How can I become proficient in coding?"

results = kb.query(
    question=query_question,
    n_results=2,
    metadata_filter={"topic": "education"},
    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()

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qa_store-0.1.5.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

qa_store-0.1.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file qa_store-0.1.5.tar.gz.

File metadata

  • Download URL: qa_store-0.1.5.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for qa_store-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f69f28f71bab8e34aa8919adee65c608461188ddcacb59696672abfc9b0f7212
MD5 02defec864c4804f6bcd1b529a0d15e2
BLAKE2b-256 cfdad0aec04714f8edc2c8b6c16217baae518efacbd25ef07fb5739cd0c12a44

See more details on using hashes here.

File details

Details for the file qa_store-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: qa_store-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for qa_store-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 570a2d5c57e2b48444600618f60bc514b0d4d8b9770d28b4f60b01861cbdb8fd
MD5 b1c8cf73d577cb28c12bb5e68d9a718c
BLAKE2b-256 2691079881629858ce9ffb3f410e06c805ac92f8333dcbbe1b6a2f6a0086c72d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page