← All work

Literary retrieval experiment / AI & apps

Giving an answer a passage to return to.

A notebook-based experiment that parses a play, embeds its passages, and retrieves relevant context for generated answers.

My role
Python / retrieval experimentation
When
2026
Built with
Python · PostgreSQL · pgvector · Sentence Transformers · Ollama · OpenRouter

Explore how it works

Try it yourself ↓
Interactive explanation · illustrative sample

Retrieval changes the context an answer receives.

Move a query vector and compare three distance measures against four invented passages.

0.8
0.3
2
ABCDquery

Context selected for an answer

  • 1. Passage D0.001

    At the gate, a messenger waits for someone to recognize the seal.

  • 2. Passage A0.010

    The traveler reaches the city, carrying a letter that no one has opened.

Lower cosine distance ranks first. Direction matters more than vector length.

The next stage would receive these passages as context. No answer is generated in this example.

Two-dimensional toy vectors explain retrieval mathematics. These are not the project’s embeddings, source play, or generated answers; no model runs here.

The challenge

A question about a long text needs relevant context. This experiment uses Romeo and Juliet to explore how parsing, chunking, and vector retrieval can connect a generated answer to the passages behind it.

How I built it

Preserve the structure of the text

The ingestion notebooks parse the play with source context, divide it into overlapping chunks, and generate embeddings for retrieval.

Explore different retrieval measures

PostgreSQL and pgvector store and query the passages, with retrieval experiments using L2 distance, cosine distance, and inner product.

Bring the retrieved passages into the answer

Notebook functions connect retrieved context to answer generation, with model experiments through Ollama and OpenRouter.

What came out of it

A set of ingestion, retrieval, and question-answering notebooks for exploring how text structure and passage selection shape answers about a literary work.

Sources & project context
  • Project notebooks and SQL implementation, reviewed October 2026
Next projectOCI DevOps lab ↗