Skip to content

Examples: (Ollama and) Vector search without an account or an API key - #134

Open
florinutz wants to merge 2 commits into
mainfrom
flo/131/ollama-example
Open

Examples: (Ollama and) Vector search without an account or an API key#134
florinutz wants to merge 2 commits into
mainfrom
flo/131/ollama-example

Conversation

@florinutz

Copy link
Copy Markdown
Contributor

Closes #131. Supersedes the embeddings half of #17.

What it does

vector_ollama.py is vector_openai.py with a different embedding backend and nothing to sign up for. Ollama runs the model in its own process and speaks HTTP, so the dependency tree gains one package rather than torch and seventeen CUDA wheels, which is where #17's sentence-transformers approach ended up. nomic-embed-text produces 768 dimensions, well inside what a FLOAT_VECTOR column accepts.

vector_search.py becomes vector_openai.py, since the backend is now the thing that tells the two programs apart.

Skipping, rather than a list of files to ignore

The suite executes every file under examples/, and CI serves no model. The runner already handles this shape for OpenAI: it catches the missing-key error and skips with a reason. This adds the same branch for Ollama's connection error, keyed on the message so an unrelated network failure still fails the test.

That leaves SKIP_FILES empty and puts the reason in the pytest report. langchain-ollama still joins the test group, because the skip only works if the import succeeds first.

Verification

Ran for real against a crate/crate:nightly container with a local Ollama serving nomic-embed-text: indexes the document and returns the correct passage for the sample query, in about four seconds, with no key set anywhere.

Both branches are exercised. With Ollama reachable the case passes; pointed at a dead port, it reports SKIPPED ... Ollama is not reachable, which is what CI will show. Full suite is 132 passed with the three pre-existing OpenAI-key failures unchanged, and ruff check, ruff format --diff and mypy . are clean.

Left alone deliberately

Both programs still read state_of_the_union.txt from a 2023 tag of langchain-ai/langchain. Moving example data into this repository is a real want — document_loader.py carries a TODO: Use new URL @ langchain-cratedb for the same reason, and #17 carried a third — but any URL pointing at this repository 404s until the file is on main, so it wants to be its own change rather than a rider on this one.

Ollama runs the embedding model in its own process and speaks HTTP, so
`vector_ollama.py` demonstrates the vector store with nothing to sign up for
and no machine learning stack in the dependency tree. `nomic-embed-text`
produces 768 dimensions, well inside what a FLOAT_VECTOR column accepts.

`vector_search.py` becomes `vector_openai.py`, now that the backend is the
thing that distinguishes the two programs.

The suite executes every example, and CI serves no model, so the runner skips
the case when it cannot reach Ollama. That mirrors how it already treats a
missing OpenAI key, and keeps the reason in the report rather than in a list
of files to ignore.
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: abec92ca-9c01-4458-bcd4-a1d5d2c1bc99

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@florinutz
florinutz requested a review from bgunebakan August 28, 2026 16:01
@florinutz florinutz self-assigned this Aug 28, 2026
@florinutz florinutz added the documentation Improvements or additions to documentation label Aug 28, 2026
@florinutz florinutz changed the title Examples: Vector search without an account or an API key Examples: (Ollama and) Vector search without an account or an API key Aug 28, 2026
@florinutz
florinutz marked this pull request as ready for review August 28, 2026 16:02
The suite executes every example, so an example's coverage records whether
the machine could reach the service it talks to. CI serves no model, so this
one is measured at the point it skips, and the number says nothing about the
code.

Its behaviour is still checked: the test runs the file wherever a server is
reachable, and a failure there is a failure.

@bgunebakan bgunebakan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added comments.

Comment on lines +23 to +24
ollama serve
ollama pull nomic-embed-text

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ollama serve waits forever so pull does not work.

Suggested change
ollama serve
ollama pull nomic-embed-text
ollama pull nomic-embed-text
ollama serve

# Optionally set environment variables to configure the Ollama and CrateDB
# endpoints.
export OLLAMA_BASE_URL="http://localhost:11434"
export CRATEDB_SQLALCHEMY_URL="crate://crate@localhost/?schema=doc"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the schema separate from the one vector_openai.py uses: both programs share the langchain_embedding table, and its vector width is fixed at 768 or 1536 by whichever of the two creates it first, so other gets vector mismatch error.

Suggested change
export CRATEDB_SQLALCHEMY_URL="crate://crate@localhost/?schema=doc"
export CRATEDB_SQLALCHEMY_URL="crate://crate@localhost/?schema=doc_ollama"

from langchain_cratedb import CrateDBVectorStore

CRATEDB_SQLALCHEMY_URL = os.environ.get(
"CRATEDB_SQLALCHEMY_URL", "crate://crate@localhost/?schema=testdrive"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

langchain_embedding table is shared between programs and its vector width is fixed when the table is first created, vector_openai.py would leave 1536 behind where this program needs 768.

Suggested change
"CRATEDB_SQLALCHEMY_URL", "crate://crate@localhost/?schema=testdrive"
"CRATEDB_SQLALCHEMY_URL", "crate://crate@localhost/?schema=testdrive_ollama"

Comment thread tests/test_examples.py
raise pytest.skip(
"Skipping test because `OPENAI_API_KEY` is not defined"
) from ex
except ConnectionError as ex:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If model didn't pulled with ollama pull it landed here and tests are skipped, I think we should catch model "nomic-embed-text" not found, try pulling it first error and raise it other than skipping so user can understand and pull the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Example: vector search without an API key

2 participants