Skip to main content

llama-index packs fuzzy_citation integration

Project description

Fuzzy Citation Query Engine Pack

Creates and runs a CustomQueryEngine -- FuzzCitationQueryEngine -- which post-processes response objects to identify source sentences using fuzzy matching.

The identified sentences are available in the response.metadata dictionary, containing a mapping of (response_sentence, source_chunk) -> {"start_char_idx": idx, "end_char_idx": idx, "node" node}. The start/end idxs represent the character indexes in the node text that the source chunk comes from.

The fuzzy matching uses fuzz.ratio() to compare sentences. The default threshold score is 50.

CLI Usage

You can download llamapacks directly using llamaindex-cli, which comes installed with the llama-index python package:

llamaindex-cli download-llamapack FuzzyCitationEnginePack --download-dir ./fuzzy_citation_pack

You can then inspect the files at ./fuzzy_citation_pack and use them as a template for your own project!

Code Usage

You can download the pack to a the ./fuzzy_citation_pack directory:

from llama_index.core import Document, VectorStoreIndex
from llama_index.core.llama_pack import download_llama_pack

# download and install dependencies
FuzzyCitationEnginePack = download_llama_pack(
    "FuzzyCitationEnginePack", "./fuzzy_citation_pack"
)

index = VectorStoreIndex.from_documents([Document.example()])
query_engine = index.as_query_engine()

fuzzy_engine = FuzzyCitationEnginePack(query_engine, threshold=50)

The run() function is a light wrapper around query_engine.query(). The response will have metadata attached to it indicating the fuzzy citations.

response = fuzzy_engine.run("What can you tell me about LLMs?")

# print source sentences
print(response.metadata.keys())

# print full source sentence info
print(response.metadata)

See the notebook on llama-hub for a full example.

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

llama_index_packs_fuzzy_citation-0.4.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_packs_fuzzy_citation-0.4.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_packs_fuzzy_citation-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ae2c5a3ce65d86358a0aae78d6cac11b8ca1622c1eca7fef0dff0cf02a490196
MD5 b8590a87cfd7ac4d5f2486f2fd079db1
BLAKE2b-256 c0edd7fddac71e09daac5b821da279360e8c825e6536cef3ec4524879cc95761

See more details on using hashes here.

File details

Details for the file llama_index_packs_fuzzy_citation-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_packs_fuzzy_citation-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 835cb4173f00084e7d433a4afc67cb70f7790113296700db44ff0eaab8f9e8e1
MD5 ea05e8b8d7407e39562035cb79f7972b
BLAKE2b-256 de0ef2f26532f331552b22c9988fcb8eb1b51c60cdcf72681d33b160b8522f0a

See more details on using hashes here.

Supported by

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