Skip to main content

Functions to conveniently run asynchronous Ollama workflows, including RAG support.

Project description

Ollama Async Logo

The functions presented in this package make it simple for researchers in social sciences to run several Large Language Models loaded through Ollama over documents stored in a data frame asynchronously (at once). As such, all models used here have to be downloaded through the Ollama interface (https://ollama.com/). With them you are able to:

  1. Analyze Text Stored in a Dataframe Column
  2. Extract Missing Metadata Information from a Text Stored in a Dataframe Column
  3. Create "Fake" LLM Survey Respondents with given characteristics and make them answer your survey questions
  4. Retrieve Information stored in a separate vector database (Retrieval Augmented Generation (RAG))

The asynchronous running of the functions is based on their ability to:

  1. Split: You run several models in parallel on many chunks of documents (the same model several times or different models per chunk). The text documents are stored as rows in a dataframe. This speeds up the computing time.
  2. Fanout: You run several models in parallel on the same chunks of documents (again, the same model several times or different models per chunk). Again, the text documents are stored as rows in a dataframe. This likewise speeds up the computing time, but primarily allows for convenient comparison of different model outputs.

The three basic functions of the package, in Async-RUN, that can either split and/or fan out over the dataframe, but do so in slightly different ways and for slightly different purposes:

  1. run_analysis(): Allows you to write one prompt, which then either splits or fans out over the text in the dataframe. The common tasks would be text labeling or sentiment analysis. The answer to the prompt might be conveniently structured in a JSON object, with specifiable keys.
  2. fill_missing_fields_from_csv(): Instead of writing a prompt, the second function is specifically designed for information extraction from the text (with the primary use case being metadata collection). It also allows for an output in a JSON format. Crucially, it also handles existing metadata information in the dataframe, so the model only extracts information that is not yet present.
  3. run_survey_responses(): The last function, instead of focusing on analysing existing text, creates fake survey responses based on a set of characteristics. The "fake" respondents are generated and stored in a data frame with the helper function generate_fake_survey_df(), which allows the creation of a representative (based on the target population) distribution of characteristics over these respondents. The use case is to have a potentially more accurate distribution of responses to survey questions prior to running the actual survey on real-life respondents.

In addition to LLM-only processing, this package supports RAG:

  1. You index your PDFs/CSVs into a FAISS or Chroma vector store, with each chunk carrying its original metadata (e.g. source filename, party label, CSV columns).
  2. At query time, the retriever fetches the top-k most relevant chunks for each input text.
  3. Those chunks are injected as “Context:” system messages before your user prompt, grounding the LLM’s answer in your corpus.
  4. This both improves factuality and lets you trace exactly which snippets (and their metadata) influenced each response.

The functions included in the Async-RAG part of the package let you simply build your own retriever database and then include in the run_analysis() pipeline:

  1. build_retriever(): A synchronous helper that ingests your PDFs and/or CSVs, splits them into overlapping chunks (either fixed‐size or sentence‐aware), embeds each chunk via Ollama (or any provided embedder), and builds a FAISS or Chroma vector index.

  2. build_retriever_async(): An async version of the above—ideal in Jupyter or any async workflow. It batches your texts into large embed requests (configurable via batch_size) and throttles concurrency (max_concurrency) to maximize throughput while avoiding overload.

  3. RAG Integration in run_analysis(): You can now pass one—or a list—of retrievers directly into run_analysis(...).

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

ollama_run_async-0.2.5.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

ollama_run_async-0.2.5-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file ollama_run_async-0.2.5.tar.gz.

File metadata

  • Download URL: ollama_run_async-0.2.5.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ollama_run_async-0.2.5.tar.gz
Algorithm Hash digest
SHA256 580cef560cbd683ebbb22263a82fc4df901ec103e8791f8badde54a019513bbc
MD5 21125c84d35897ac851b5914d70e210a
BLAKE2b-256 ecfdf3cafa5fbb50a480a1c1f2f250f778f75e7a5a2a7ef8aba07aa4d77f00b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ollama_run_async-0.2.5.tar.gz:

Publisher: python-publish.yml on Quikii/Ollama-run-async

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ollama_run_async-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for ollama_run_async-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6cbb247b2e2b2c33e4eb09e35ca453e9cfab69e8ba629749a8614e1dc07ff0b9
MD5 192652fc22fa3afac1d3a7642a83093f
BLAKE2b-256 5841259fa0e97ea83e2677fb1de2ad3baeb18fae007e16f62496343c733ea5aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for ollama_run_async-0.2.5-py3-none-any.whl:

Publisher: python-publish.yml on Quikii/Ollama-run-async

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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