Skip to main content
Pure semantic search retrieves the most similar documents to your query using only vector similarity. No metadata filters are applied — all documents in the collection are candidates. Use pure semantic search when you want broad retrieval across your entire document corpus without restricting results by category, date, or other metadata. Before running this example, make sure you have a VectorAI DB instance running at localhost:6574 and the relevant SDK installed. For setup instructions, see Docker installation. This example demonstrates the core semantic search pipeline:
  1. Create a collection with cosine distance and a vector dimension matching your embeddings.
  2. Create field indexes on payload fields you plan to filter on later.
  3. Embed and upsert documents with their text, vector, and metadata payload.
  4. Search with a query vector and retrieve the top-K most similar results with their payload.
Each result includes these fields:
  • id: The unique identifier of the matching document
  • score: Cosine similarity score. Higher values indicate greater semantic similarity.
  • payload: Metadata object containing the document text and attributes
In production, replace the placeholder embedding function (fake_embed in Python, fakeEmbed in JavaScript) with a real embedding model such as OpenAI, Cohere, or an open-source model like Sentence Transformers. Use the same model for both indexing and querying.