Skip to main content
This complete workflow demonstrates an end-to-end semantic search pipeline. It covers collection setup, document embedding, field indexing, and all major search strategies: pure semantic search, filtered search, range-filtered search, score threshold search, and multiconstraint search. This mirrors a real-world RAG (Retrieval-Augmented Generation) pipeline where you encode a query, search for similar documents, and filter by 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 workflow covers five search strategies:
  1. Pure semantic search — Retrieves the top five most similar documents with no filters applied. All documents are candidates.
  2. Keyword-filtered search — Restricts results to documents with topic="ml" while ranking by vector similarity.
  3. Range-filtered search — Restricts results to documents with year >= 2023 while ranking by vector similarity.
  4. Score threshold search — Returns only results with a cosine similarity score of 0.5 or higher. The result count may be less than limit.
  5. multiconstraint search — Combines a keyword filter (topic="ml") with a range filter (year >= 2024). Both conditions must be true.

Key patterns

Keep these practices in mind when building your own semantic search pipeline.
  • Create field indexes before searching — Call create_field_index (Python) or createFieldIndex (JavaScript) for each payload field used in filters. This enables efficient filter evaluation during search.
  • Use the same embedding model for indexing and querying — Vector similarity is only meaningful when both sides use the same model.
  • Combine strategies as needed — Score thresholds and metadata filters can be used together for maximum precision.
In production, replace the placeholder embedding function (fake_embed in Python, fakeEmbed in JavaScript) with a real embedding model. For a ready-to-use example, see OpenAI embedding integration.