eliranwong / UniqueBible

A cross-platform bible application, integrated with high-quality resources and amazing features, running offline in Windows, macOS and Linux, ChromeOS, Android, iOS. Various running modes are supported.
https://UniqueBible.app
GNU General Public License v3.0
122 stars 34 forks source link

use LlamaIndex to search bibles? #1363

Closed eliranwong closed 1 year ago

eliranwong commented 1 year ago

will explore the possibility of using LlamaIndex for searching bibles

https://gpt-index.readthedocs.io/en/stable/

eliranwong commented 1 year ago

an example to search commentary on James: https://github.com/BibleTools/commentary_59_James_English/blob/main/semantic_search.py

eliranwong commented 1 year ago

example of search sqlite bible module:

from sqlalchemy import create_engine from llama_index import SQLDatabase, GPTSQLStructStoreIndex, StorageContext, load_index_from_storage import config, openai, os

""" An example of searching via llama_index

documentation: https://gpt-index.readthedocs.io/en/latest/index.html """

openai.api_key = os.environ["OPENAI_API_KEY"] = config.openaiApiKey openai.organization = config.openaiApiOrganization

engine = create_engine("sqlite:///AGB.bible") sql_database = SQLDatabase(engine=engine, include_tables=["Verses"])

reference: https://gpt-index.readthedocs.io/en/latest/reference/indices/struct_store.html

""" index = GPTSQLStructStoreIndex( [], sql_database=sql_database, table_name="Verses", ) index.storage_context.persist(persist_dir="storage") """

rebuild storage context from local directory "storage"

storage_context = StorageContext.from_defaults(persist_dir="storage")

load index

index = load_index_from_storage(storage_context, sql_database=sql_database)

query_engine = index.as_query_engine() response = query_engine.query("book=43, scripture contains Jesus and love") print(response) print(type(response))

eliranwong commented 1 year ago

another example:

https://github.com/eliranwong/AmazingGraceBibleTranslationSeries/blob/main/tools/semantic_search.py

eliranwong commented 1 year ago

integrated in https://github.com/eliranwong/UniqueBible/commit/16f91a3a38d6977ca6545f525bfe09350af8d03e

eliranwong commented 1 year ago
book_menu
eliranwong commented 1 year ago
openai_api_key
eliranwong commented 1 year ago
master_search