• Org-Ql Query Prompt

    Use the following prompt to return an org-ql s-expression based on the user’s input. This can be used along with calling org-ql from the command line to make an LLM tool that can query org-mode tasks and headings.

    You are an AI assistant designed to help convert natural language questions into org-ql queries for use with Org mode in Emacs. org-ql queries are used to filter and search for specific entries in Org files based on various criteria like tags, properties, and timestamps.

    Instructions:

    1. Read the user’s question carefully.
    2. Identify the key criteria mentioned in the question (e.g., tags, properties, deadlines, scheduled dates, priorities, etc.).
    3. Construct an appropriate org-ql query that reflects the user’s criteria.
    4. Only return the org-ql query with no other text or explanation

    Examples:

    User Question:

    โ€œFind all tasks that are due this week and have the tag ‘work’.โ€

    Converted org-ql Query:

    (org-ql-select (org-agenda-files) ‘(and (deadline :from today :to +7d) (tags “work”)) :action ‘(org-get-heading t t))

    User Question:

    โ€œShow me notes with the tag ‘meeting’ that were created last month.โ€

    Converted org-ql Query:

    (org-ql-select (org-agenda-files) ‘(and (tags “meeting”) (timestamp :from -1m :to today)) :action ‘(org-get-heading t t))

    User Question:

    โ€œList all tasks with priority ‘A’ that are scheduled for tomorrow.โ€

    Converted org-ql Query:

    (org-ql-select (org-agenda-files) ‘(and (priority “A”) (scheduled :on +1d)) :action ‘(org-get-heading t t))

    User Question:

    โ€œFind all entries tagged ‘home’ that have a deadline next week.โ€

    Converted org-ql Query:

    (org-ql-select (org-agenda-files) ‘(and (tags “home”) (deadline :from +7d :to +14d)) :action ‘(org-get-heading t t))

    User Question:

    โ€œShow tasks that are not done and have the tag ‘project’.โ€

    Converted org-ql Query:

    (org-ql-select (org-agenda-files) ‘(and (todo) (tags “project”)) :action ‘(org-get-heading t t))

    User Question:

    โ€œFind all tasks with a priority of ‘B’ that were created this month.โ€

    Converted org-ql Query:

    (org-ql-select (org-agenda-files) ‘(and (priority “B”) (timestamp :from -1m :to today)) :action ‘(org-get-heading t t))

    User Question:

    {question}

    Converted org-ql Query:


  • Org-Ql From the Command Line

    Most of my tasks and projects are organized using org-mode. I was looking for a way to query them from an LLM and, rather than recreate an index and a database, I can use what I normally use, org-ql using emacs in batch mode.

    Here’s how to run org-ql from the command line.

    emacs --batch -l $HOME/.emacs.d/init.el --eval "(message (with-output-to-string (princ (mapconcat 'identity (org-ql-select (org-agenda-files) '(todo \"WAITING\") :action '(org-get-heading t t)) \"\n\"))))"
    

    Each matching result will be printed out on a newline. This can then be used for further processing by capturing stdout.


  • How to Get Org-Mode Filetags

    I recently needed to change the behavior of a library (org-download) based on the tags of the current buffer. Most of the answers I found online are incorrect (and so was ChatGPT) for Org version 9.5.

    Here’s how to get the filetags of an org-mode buffer or file programatically:

    (org-collect-keywords '("FILETAGS"))
    

    I used this to write a function to check whether or not the org-mode file was private or not.

    (defun my/org-file-is-private ()
        (let ((tags (car (cdr (car (org-collect-keywords '("FILETAGS")))))))
          (if (stringp tags)
              (member "private" (split-string tags))
            nil)))
    

  • Sorting Vector Store Results

    Many vector databases can find the top k most similar results to a query but are unable to sort by other document metadata. This is a pretty severe limitation for building LLM applications, especially for ones where time is dimension (meetings, calendars, task lists, etc.). For example, retrieving the 10 most similar results to the phrase “team meeting notes” but not being able to retrieve the team meeting notes from the last month.

    To work around the limitation of sorting vector query results, the most common suggestion is to pre-process a query or run multiple queries with different strategies at once and then combine the results. For example, first query for documents with a string similar to “meeting notes” (maybe using fuzzy, full-text search) filtered by date, then constrain a vector query search based on the collection of filtered records, and then pass the results to an LLM to synthesize the results and respond.

    See also:


  • Alfred Snippets on IOS

    Alfred does not have a mobile application that can make snippets available from your desktop to your phone. Here’s how to use Shortcuts on iOS to do that.

    First, export your snippets in Alfred by going to Features -> Snippets -> right click the collection and select Export and save the file to Dropbox.

    Next, create a shortcut on your phone with the following.

    (Not pictured in the screenshot, add a step to copy the value to your clipboard or do something else with the value)

    Now when you run the shortcut, you’ll be able access your snippets on your phone.

    Make sure to replace the file path with the path to your snippets file stored in Dropbox. This also works if you store the file someplace else because the file that Alfred stores for snippets is a zipped json file.


  • How to Build an Intuition of What AI Can Do

    One of the difficult parts of applying AI to existing processes and products is that people aren’t calibrated on what generative AI can and can’t do. This leads to both wild ideas that are not possible and missed opportunities to automate seemingly difficult work that is possible.

    How do you build an intuition of what AI can do?

    There’s no substitute for trying out these tools on your own. Not just fiddling around with ChatGPT but actually trying to solve a real problem using LLMs. Surprise plus memory equals learning, so the more things you try, the more surprises you will encounter, and the more you can learn about what it can and can’t do.

    Speaking for myself, I’ve been quietly working on one of one software that helps me explore the latest AI advancements in a safe place. I built org-ai to try out RAG techniques over a large number of documents (my public and private notes). I then applied what I learned to a prototype at work using the same techniques. From there I spotted problems with prompts and retrieving relevant documents that helped me understand some limitations of vector databases and RAG.

    I’m documenting a list of prompts that I can reuse for various problems. I wrote a script to use AI in a Google spreadsheet and wrote a prompt to detect specific kinds of spam signups. I wrote a prompt to help summarize the last week and communicate it to the team based on previous examples to match my writing style.

    Once you build up the habit of applying AI to real problems it starts to become a default starting point for new solutions. Not everything can or should be solved with AI but as a way to rapidly explore the space and gain real-world experience, learning by doing is unmatched.


  • Use AI in a Google Sheets

    I want to be able to use generative AI in spreadsheets to solve unique problems. I want to call OpenAI from a cell that passes in a prompt and a value from a column then returns an answer I can easily parse.

    Thankfully, you can do this in Google Sheets and Apps Script!

    First, create the script using App Script. In your spreadsheet go to Extensions -> Apps Script then add the script.

    function AI(prompt, value) {
      // Replace YOUR_API_KEY with your actual OpenAI API key
      const apiKey = 'YOUR_KEY';
      const apiURL = 'https://api.openai.com/v1/chat/completions';
    
      const payload = JSON.stringify({
        "model": "gpt-4-turbo",
        "frequency_penalty": 0,
        "presence_penalty": 0,
        "temperature": 0,
        "messages": [
          {"role": "system", "content": `${prompt}`},
          {"role": "user", "content": `${value}`}
        ]
      });
    
      const options = {
        "method": "post",
        "contentType": "application/json",
        "payload": payload,
        "headers": {
          "Authorization": "Bearer " + apiKey
        },
        "muteHttpExceptions": false
      };
    
      try {
        const response = UrlFetchApp.fetch(apiURL, options);
        const json = JSON.parse(response.getContentText());
        const resultText = json.choices[0].message.content;
        return resultText;
      } catch (e) {
        Logger.log(e.toString());
      }
    }
    

    Finally, call the App Script from a cell like you would any formula =AI(PROMPT, COLUMN).

    (Based on this thread in the OpenAI forum)

    See also:


  • Pricing for a Wide Range of Company Sizes

    When selling a B2B SaaS product to a wide range of company sizes (e.g. SMB, mid-market, enterprise), you generally want smaller companies to pay less and larger companies to pay more. This makes pricing difficultโ€”make it too one-size-fits-all and you can accidentally price out the smaller customers, make it too a la carte, and all customers will find your pricing confusing.

    What are some pricing techniques you can use when you have a wide range of business sizes to sell to?

    Pricing tiers using caps

    If you design pricing plans around the expected size of customer, you can make it clear who should be buying which plan and make a natural upgrade path. One way to do this is to include caps around one of the variable like the number of employees. For example, plan A is for up to 50 employees, plan B up to 500 employees, and so on.

    Simple and advanced

    Providing versions of the same feature can be used to appeal to different size customers and signal to the bigger companies which plans they should be on. For example, you might provide hosting on the basic plan for SMBs but faster CDN for mid-market companies and the ability to set custom headers for enterprises.

    Add-ons

    Pricing with tiered plans (which is most common for SaaS) comes with the downside that their may be a few critical features that a customer really needs but is stuck between plans. Using add-ons allows customers to pull forward from higher plans to get what they need. Have 51 employees and the cap is 50? Provide an upsell for each additional employee after the cap. Really need a CDN because you are an e-commerce shop? Purchase the CDN add-on for the basic plan.

    See also:


  • Shawn's Eskimo

    In an episode of Boy Meets World, Shawn is in a competition of who can wait longest on a billboard suspended high up in the air in order to win tickets to the Super Bowl. He stays there until the only two people left on a cold night are him and an Eskimo eating ice cream.

    When Corey tries to talk him down (literally), Shawn tells him that he has to stay. All his life there was always something in his way, preventing him from what he wanted to achieve.

    Shawn finally gives up on the contest, but goes to San Diego on his own, eventually finding a way into the Super Bowl.

    While the lesson of the episode was that Corey can’t solve all of Shawn’s problems for him, I remember it differentlyโ€”there will always be someone better than you no matter how hard you try, but that is not a reason to give up. There is more than one path.


  • Getting Ready for AI

    The other day I noticed a tweet from Justin Duke which outlined a plan to get his company’s codebase ready for Devinโ€”a programming focused generative AI product. While many are skeptical about AI taking over coding tasks, progress happening quickly and it seems likely that these tools will help software engineers, though maybe not replace the job outright).

    If we think AI can positively impact many domains, the question becomes, how can we position ourselves today to take advantage of it in the future?

    Writing more is almost certainly one way. Large language models operate on content. That content is mostly text. If you want to have a future co-pilot that can help you build useful and unique knowledge (and potentially avoid knowledge collapse), it’s reasonable to believe you need to be writing a heck of a lot so that AI can draw from what you already know. For example, in a video of Reid Hoffman interviewing himself as an AI, the AI was trained on every book Reid has written and every talk he’s given.

    When it comes to code, writing comments explaining what the code is doing and why that’s important seems like it would help generative AI make better contributions that need less supervision. After all, reading someone else’s code is hard enough! I would love to read some research on performance improvements not just on writing code but about comprehension of business logic and how documentation helps or hurts.

    Running a business, building a culture where writing is thinking and the primary way teams work asynchronously will amplify every future investment in AI. When Notion rolled out their AI-powered search, a new hire at Mosey started asking it questions about projects, tools, processes, and terms he didn’t understandโ€”the responses helped him get up to speed quickly. FAQs don’t work, but being able to respond to almost any question however it’s formulated sure does!


  • Net Magic Number

    Net magic number is a measurement of go-to-market (GTM) efficiency for SaaS businesses. A magic number less than 1.0 indicates the business will lose money on each customer. Top SaaS businesses making less than $25MM in revenue per year have a magic number of 1.7 according to benchmarks from Iconiq Capital as in their business returns 1.7x for every sales and marketing dollar they spent to acquire customers.

    Net magic number is calculated by taking the current quarter’s revenue less previous quarter’s revenue times 4 divided by the previous quarter’s sales and marketing spend.

    By looking at the previous quarter, net magic number accounts for the average sales cycle to complete which makes it a better measurement for enterprise SaaS that has a sales motion.

    See also:


  • Data Marketing

    When companies run surveys and industry analysis that they share with the media, they’re gaining exposure for themeselves. While data may be contained within a blog post or report, the unit of value is the data point that a journalist can extract into their article (with a mention of the source).