{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from leann.api import LeannBuilder, LeannSearcher, LeannChat\n", "\n", "# 1. Build the index (no embeddings stored!)\n", "builder = LeannBuilder(backend_name=\"hnsw\")\n", "builder.add_text(\"C# is a powerful programming language\")\n", "builder.add_text(\"Python is a powerful programming language and it is very popular\")\n", "builder.add_text(\"Machine learning transforms industries\")\n", "builder.add_text(\"Neural networks process complex data\")\n", "builder.add_text(\"Leann is a great storage saving engine for RAG on your MacBook\")\n", "builder.build_index(\"knowledge.leann\")\n", "\n", "# 2. Search with real-time embeddings\n", "searcher = LeannSearcher(\"knowledge.leann\")\n", "results = searcher.search(\"programming languages\", top_k=2)\n", "\n", "# 3. Chat with LEANN using retrieved results\n", "llm_config = {\n", " \"type\": \"ollama\",\n", " \"model\": \"llama3.2:1b\"\n", "}\n", "\n", "chat = LeannChat(index_path=\"knowledge.leann\", llm_config=llm_config)\n", "response = chat.ask(\n", " \"Compare the two retrieved programming languages and say which one is more popular today.\",\n", " top_k=2,\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.12" } }, "nbformat": 4, "nbformat_minor": 2 }