Turso: Databases For All Your AI Apps

Glauber CostaGlauber Costa
Cover image for Turso: Databases For All Your AI Apps

Today we’re announcing that our native vector search feature is generally available, including indexing using the DiskANN algorithm. Alongside that we are introducing the Turso Vector SDK, which makes it easier than ever to do local vector search, and 1 bit quantization, which can net LLMs huge efficiency gains. Finally, we are excited to announce today that LangChain now supports libSQL as a vector store.

With these announcements, Turso becomes the best database for all your AI applications.

Let’s first look at a couple of killer use cases from our partners that are running in production, available for you to try right now. Then, further down in the article we’ll deep dive on the features we just announced.

#Multitenant AI with Adaptive Computer

Ever heard of ephemeral databases? You will. AI agents that go and actually do stuff for users - like build a website, change an app’s code etc, - are becoming more common. AI agents need to quickly be able to spin up and branch databases as workspaces to implement requested changes which can be quickly accepted or rolled back / destroyed if mistakes are made. Turso now allows you to create unlimited databases in our self-service plans. So you can easily scale up LLM based AI agent apps that let users use natural language to build.

Here’s an example of this being done in production, right now:

Adaptive Computer One is an AI that lets you modify and build user interfaces using a natural language LLM input. For example, imagine telling an LLM to change the color of a button in an interface you’re building. They use Turso’s platform API to programmatically spin up ephemeral databases, sometimes hundreds or even thousands for a single AI agent’s tasks, to quickly spawn a data store for use for a given task. They also use Branching to quickly rollback any unwanted or unexpected changes an AI Agent might make on behalf of a user. This single use database approach derisks, simplifies and speeds up their ability to put AI to work, and it effortlessly scales without breaking the bank.

Read more in our Adaptive Computer case study.

#Mobile AI with Kin

Kin is a local first mobile app for iOS that offers a personal AI assistant which learns from you in order to become a hybrid coach / confidant / friend / advisor. Because it’s such an intimate use case, Kin is very privacy focused. That’s one of the reasons they are local first, focusing on doing as much on the mobile device as possible, without needing to send your data to a 3rd party server for parsing.

That’s why Kin uses libSQL’s inbuilt vector data type support to deliver on device, local vector search. This enables them to honestly say that they never see your data, because they don’t even have a cloud service to host your data. It’s all on device, and vector similarity search happens on device as well.

There are other benefits to this approach. For example, Kin has a long ingestion pipeline that’s extracting everything, and because they’re using vector embeddings within the SQLite file, the vectors can be used together with your on device relational data, and come at no additional cost - they count as normal rows that can be read or written.

And because Kin is a mobile app, using an native, local vector search solution within SQLite is really the best way to scale into production. Using one database for everything instead of having to use a separate database just for the vector use case isn’t really the only viable solution from a fault tolerance, computational, cost and scale perspective.

Read more in our Kin Case Study.

We’ll have many more Mobile and Local First related announcements as Turso Launch Week 3 goes on, so stay tuned!

Now, more details on each feature announcement.

#Vector Search is now GA

To build an AI app with today’s LLMs one of the most fundamental things you need is to be able to support vector similarity search. You used to have to use extensions or separate, dedicated vector databases to do this, but earlier this year, we announced a feature preview of our native Vector Search implementation. Today, this feature reaches GA.

Thanks to our fork of SQLite, Turso’s vector search integrates deeply with the SQLite query language, and doesn’t depend on any extension. It is always enabled, and can be used on the Turso platform, or fully offline on your mobile device, allowing for fully private inference.

You can also do combined queries for vector and other uses for greater efficiency, all with zero network latency if you’re doing it locally.

Here’s an example of the kind of query you can write using our native vector search:

SELECT *
FROM
  movies
WHERE
  year >= 2020
ORDER BY
  vector_distance_cos(embedding, '[3,1,2]')
LIMIT 3;

More details on our docs

#Vector SDK

We get it, dealing with Vector Embeddings and SQL can be complex.

Today we are excited to release a preview of a new LibSQL Vector SDK.

Whether you’re inserting one or many vectors at once, the new SDK makes it super easy to upsert your database with embeddings:

const options: IndexOptions = {
  tableName: 'movies',
  dimensions: 1024,
  columns: [
    { name: 'title', type: 'TEXT' },
    { name: 'year', type: 'INTEGER' },
    { name: 'plot_summary', type: 'TEXT' },
    { name: 'genres', type: 'TEXT' },
  ],
};

const movieIndex = new Index(client, options);
await movieIndex.initialize();

await movieIndex.upsert([
  {
    id: 'halloween_1978',
    vector: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], // Dummy vector
    title: 'Halloween',
    year: 1978,
    plot_summary:
      'Fifteen years after murdering his sister on Halloween night 1963, Michael Myers escapes from a mental hospital and returns to the small town of Haddonfield, Illinois to kill again.',
    genres: 'Horror,Thriller',
  },
  {
    id: 'ghostbusters_1984',
    vector: [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1], // Dummy vector
    title: 'Ghostbusters',
    year: 1984,
    plot_summary:
      'Three former parapsychology professors set up shop as a unique ghost removal service in New York City, attracting frightful customers and skeptical police attention.',
    genres: 'Action,Comedy,Fantasy',
  },
  {
    id: 'beetlejuice_1988',
    vector: [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2], // Dummy vector
    title: 'Beetlejuice',
    year: 1988,
    plot_summary:
      'The spirits of a deceased couple are harassed by an unbearable family that has moved into their home, and hire a malicious spirit to drive them out.',
    genres: 'Comedy,Fantasy',
  },
]);

When you’re ready to perform a similarity search, the query function abstracts the SQL:

const query = “Looking for a scary movie for Halloween”;

const queryEmbedding = await generateEmbedding(query);

const results = await movieIndex.query(queryEmbedding, { topK: 5 });

The Vector SDK is currently available via NPM for TypeScript, but will soon be available in other languages as we seek feedback from the community. Join us on Discord to share your thoughts on how we can improve this.

#1-bit quantization

Sometimes, using as little storage as possible is important. For those times, we now support 1-bit quantization, which can result in up to a 32x reduction in size.

1-bit quantization is a technique in which instead of storing a full vector, only a binary value is stored. This is true for both the table and the index.

The main advantage is space savings. For example, a 512-dimensional vector requires 2 KiB of space with 32-bit floating point values, which is a lot. With 1-bit representation, you only need 64 bytes.

But being able to scan through more vectors at once, both in the table and the index, lookups are also faster.

In many use cases, 1-bit quantization provides results that are accurate enough, while using significantly less storage. While every vector can be compressed to a single bit, results tend to be better when a model that is 1-bit aware is used.

The Mixedbread models are 1-bit aware, and pair well with Turso’s 1-bit quantization support.

To use 1-bit quantized vectors, all you have to do is create your vectors with the FLOAT1BIT type.

More info on how to use 1-bit quantization on our documentation.

#LangChain VectorStore

The LangChain framework makes building LLM driven applications fast, easy and fun.

Today we are excited to announce that LangChain now supports libSQL as a vector store.

The new libSQL vector store for LangChain enables AI developers to store and search embedded data using Turso's libSQL Vector support. It works with both remote and local libSQL instances, including offline retrieval from embedded replicas.

To set up:

import { LibSQLVectorStore } from '@langchain/community/vectorstores/libsql';
import { OpenAIEmbeddings } from '@langchain/openai';
import { createClient } from '@libsql/client';

const embeddings = new OpenAIEmbeddings({ model: 'text-embedding-3-small' });
const libsqlClient = createClient({
  url: 'libsql://…',
  authToken: '...',
});

const vectorStore = new LibSQLVectorStore(embeddings, {
  db: libsqlClient,
  tableName: 'TABLE_NAME',
  embeddingColumn: 'EMBEDDING_COLUMN',
  dimensions: 1536,
});

To insert documents:

import type { Document } from '@langchain/core/documents';

const documents: Document[] = [
  { pageContent: 'Hello', metadata: { topic: 'greeting' } },
  { pageContent: 'Bye bye', metadata: { topic: 'greeting' } },
];

await vectorStore.addDocuments(documents);

Similar to the Vector SDK, it’s super easy to query with similarity search by avoiding the complexity of writing SQL:

const results = await vectorStore.similaritySearchWithScore('hola', 1);

for (const [doc, score] of results) {
  console.log(
    `${score.toFixed(3)} ${doc.pageContent} [${JSON.stringify(doc.metadata)}]`,
  );
}

Filtering by other fields in the embedding table will be supported in the next update

#Conclusion

With the launches today, Turso solidifies its position as the best database for all your AI applications. Whether you’re rolling out a “traditional” LLM application and just need a great database, using multitenant ephemeral databases for AI agents, building on device, local first, mobile AI apps or anything in between, you can trust Turso to deliver in production.

Get started today — We can’t wait to see what you build.

scarf