What is semantic search? Semantic search, generally based on embedding models, is important to large language model apps because of the limited context size of models. It enables the retrieval of chunks of valuable information that fit in context to perform a particular task. This is called Retrieval-Augmented Generation (RAG).
Data Source creation
Creating a Data Source simply consists in providing a name and a description.Parameters
name: string. The name of the new Data Source. It should be short and can only contain lowercase alphanumerical characters as well as-.description: optional string.
Document insertion
Once a Data Source is created, documents can be inserted from the Dust interface or by API. When a document is inserted, the following happens automatically:- Chunking: The document is pre-processed to remove repeated whitespaces (helps semantic search) and chunked using
max_chunk_sizetokens per chunk. - Embedding: Each chunk is embedded (in parallel, with retries) using the embedding model
text-embedding-3-largefrom OpenAI. Enterprise plan customers can ask for a different embedding model of their choice. - Indexing: Each resulting embedding vector is inserted in a vector search database along with metadata about the document and the original chunk text.
Parameters
document_id: string. A unique ID for the document. The semantics of the insertion really is an upsertion. Inserting with adocument_idthat does not exist will create that document; it will otherwise replace the previous document version (removing previous chunks from the vector search database and replacing by the updated document’s).text: string.
Uploading directories of files to your Data Source
We also have a script you can use to upload a directory’s contents to your data source. Copy the following code intoupload.py and then fill in the values for your Dust API key, the workspace ID you are in, and the data source you want to upload to. Then run python upload.py <dir>, where dir is the directory from which you want to upload the documents.
python upload.py test_dir/.
Document deletion
When deleting a document, all associated chunks are automatically removed from the vector search database of the Data Source. Documents can be deleted from the Dust interface or by API.Data sources can be deleted from the Dust interface. When deleted, all associated data (all documents and associated chunks) are deleted from our systems.
Querying a Data Source
Querying a Data Source is done using the Datasource block. Thedata_source block returns a list of Document objects. Each document may include one or more chunks (the chunks returned by the semantic search are aggregated per document). See Chunks and Documents for more details.
When a query is run the following happens automatically:
- Embedding: The query is embedded using the embedding model set on the Data Source.
- Search: A vector search query is run against the embedding vectors of the Data Source’s documents’ chunks.
- Union: Most relevant chunks’ documents are retrieved and chunks are associated to their original document object.