Skip to content

This content is still in French

The page itself is translated, but its detailed content is not yet. Hardware sheets, guides and catalogues are still shown in French: we would rather give you the original than a rough machine translation. View the French site

Chercher et répondre

python
# demander.py
import sqlite3, sqlite_vec, requests, struct, sys

OLLAMA, DIMENSION = "http://localhost:11434", 384
question = " ".join(sys.argv[1:])

def vecteur(t):
    return requests.post(f"{OLLAMA}/api/embeddings",
                         json={"model": "zylonai/multilingual-e5-small", "prompt": t}).json()["embedding"]

base = sqlite3.connect("corpus.db")
base.enable_load_extension(True)
sqlite_vec.load(base)

q = struct.pack(f"{DIMENSION}f", *vecteur(question))
lignes = base.execute("""
    SELECT p.source, p.texte FROM vecteurs v
    JOIN passages p ON p.id = v.id
    WHERE v.v MATCH ? AND k = 4
    ORDER BY distance
""", (q,)).fetchall()

extraits = "\n\n".join(f"[{s}] {t}" for s, t in lignes)

prompt = f"""Réponds uniquement à partir des extraits ci-dessous.
Si la réponse ne s'y trouve pas, dis-le clairement.
Cite la source entre crochets.

Extraits :
{extraits}

Question : {question}"""

r = requests.post(f"{OLLAMA}/api/generate",
                  json={"model": "qwen3:4b", "prompt": prompt, "stream": False})
print(r.json()["response"])
shell
python demander.py "Quelles sont les conditions d'inscription ?"