Skip to main content

We believe that hallucinations pose a major problem in the adoption of LLMs (Language Model Models). It is imperative to provide a simple and quick solution that allows the user to verify the coherence of the answers to the questions they are asked. Don't forget that even answers to questions can be subject to hallucinations

The conventional approach is to provide a list of URLs of the documents that helped in answering (see qa_with_source). However, this approach is unsatisfactory in several scenarios:

  1. The question is asked about a PDF of over 100 pages. Each fragment comes from the same document, but from where?
  2. Some documents do not have URLs (data retrieved from a database or other loaders).

Other technical considerations make the URL approach tricky. This is because prompts do not work well with complex URLs. This consumes a huge number of tokens, and in the end, the result is too big.

It appears essential to have a means of retrieving all references to the actual data sources used by the model to answer the question. It is better to return a list of Documents than a list of URLs.

This includes:

  • The precise list of documents really used for the answer (the Documents, along with their metadata that may contain page numbers, slide numbers, or any other information allowing the retrieval of the fragment in the original document).
  • The excerpts of text used for the answer in each fragment. Even if a fragment is used, the LLM only utilizes a small portion to generate the answer. Access to these verbatim excerpts helps to quickly ascertain the validity of the answer.

We propose a two pipelines: qa_with_reference and qa_with_reference_and_verbatims for this purpose. It is a Question/Answer type pipeline that returns the list of documents used, and in the metadata, the list of verbatim excerpts exploited to produce the answer. It is very similar to qa_with_sources_chain in that it is inspired by it.

If the verbatim is not really from the original document, it's removed.

Install

pip install langchain-qa_with_reference

Sample notebook

See here

langchain Pull-request

This is a temporary project while I wait for my langchain pull-request to be validated.

It's experimental

For the moment, the code is being tested in a number of environments to validate and adjust it. The langchain framework is very instable. Some features can become depreciated. We work to maintain compatibility as far as possible.

Metadata

Release files for langchain-qa-with-references 0.0.330

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

Source distribution (sdist)

Source distribution for langchain-qa-with-references 0.0.330
File Size Uploaded Provenance Actions
langchain_qa_with_references-0.0.330.tar.gz 19.7 kB Without provenance Details for langchain_qa_with_references-0.0.330.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-qa-with-references 0.0.330
File Interpreter ABI Platform Actions
langchain_qa_with_references-0.0.330-py3-none-any.whl Python 3 none any Details for langchain_qa_with_references-0.0.330-py3-none-any.whl

Total release size: 49.0 kB

Release files / langchain_qa_with_references-0.0.330.tar.gz

Download URL langchain_qa_with_references-0.0.330.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b27709deda0ef7af7cf1d6c43fa937fc4bc7a957eda4a6cf235c36ca4798233a
BLAKE2b-256 checksum
How to use checksums
a4560ef1a137fbdad4b3ea7977b9cd9219484bf7205801391e9aa8e220af0573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / langchain_qa_with_references-0.0.330-py3-none-any.whl

Download URL langchain_qa_with_references-0.0.330-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb79629a7440be05aa21ba9ec00e1c0649b651f8ebf3530c058d420d2484c482
BLAKE2b-256 checksum
How to use checksums
f077414537583d8caf4392f100dcb0ad2e06c319394b897002fac237d399c537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Security for langchain-qa-with-references 0.0.330

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.

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