Search my code examples

Run searches against all of the code examples I have ever included on my blog.

Owned by simonw, visibility: Public

Query parameters

SQL query
with results_stripped as (
  select id, title,
    replace(replace(replace(replace(replace(regexp_replace(
      (regexp_matches(body, '<pre>(.*?)</pre>', 'g'))[1],
        E'<[^>]+>', '', 'gi'
      ), '&quot' || chr(59), '"'), '&gt' || chr(59), '>'), '&lt' || chr(59), '<'), '&#039' || chr(59), chr(39)), '&amp' || chr(59), '&'
    ) as code
  from
    blog_entry
  where
    body ~ '<pre>.*<pre>'
)
select id, title, code, 'https://simonwillison.net/e/' || id as link from results_stripped
where code like '%%' || %(search)s || '%%' order by id desc limit 10

10 rows

id title code link
8382 Building search-based RAG using Claude, Datasette and Val Town // The SQL query from earlier const sql = `select blog_entry.id, blog_entry.title, blog_entry.body, blog_entry.created from blog_entry join blog_entry_fts on blog_entry_fts.rowid = blog_entry.rowid where blog_entry_fts match :search order by rank limit 10`; async function runSearch(keywords) { // Turn the keywords into "word1" OR "word2" OR "word3" const search = keywords.map(s => `"${s}"`).join(" OR "); // Compose the JSON API URL to run the query const params = new URLSearchParams({ search, sql, _shape: "array", }); const url = "https://datasette.simonwillison.net/simonwillisonblog.json?" + params; const result = await (await fetch(url)).json(); return result; } https://simonwillison.net/e/8382
8382 Building search-based RAG using Claude, Datasette and Val Town select blog_entry.id, blog_entry.title, blog_entry.body, blog_entry.created from blog_entry join blog_entry_fts on blog_entry_fts.rowid = blog_entry.rowid where blog_entry_fts match :search order by rank limit 10 https://simonwillison.net/e/8382
8380 Language models on the command-line llm embed-multi links \ -d simonwillisonblog.db \ --sql 'select id, link_url, link_title, commentary from blog_blogmark' \ -m 3-small --store https://simonwillison.net/e/8380
8380 Language models on the command-line select id, link_url, link_title, commentary from blog_blogmark https://simonwillison.net/e/8380
8327 Interesting ideas in Observable Framework ```js echo const packageName = view(Inputs.select(packages, { value: "sqlite-utils", label: "Package" })); ``` https://simonwillison.net/e/8327
8327 Interesting ideas in Observable Framework ```js echo const packages_sql = "select package from stats group by package order by max(downloads) desc" ``` ```js echo const packages = fetch( `https://datasette.io/content.json?sql=${encodeURIComponent( packages_sql )}&_size=max&_shape=arrayfirst` ).then((r) => r.json()); ``` https://simonwillison.net/e/8327
8326 Weeknotes: Getting ready for NICAR dclient query https://datasette.io/content \ "select * from news limit 3" https://simonwillison.net/e/8326
8296 Embeddings: What they are and why they matter select id, hex(embedding) from embeddings https://simonwillison.net/e/8296
8296 Embeddings: What they are and why they matter select id, llm_embed_decode(embedding) from embeddings limit 10 https://simonwillison.net/e/8296
8296 Embeddings: What they are and why they matter select id, llm_embed_cosine( embedding, ( select embedding from embeddings where id = 'sqlite_sqlite-tg.md' ) ) as score from embeddings order by score desc limit 5 https://simonwillison.net/e/8296
Copy and export data

Duration: 161.55ms