Skip to main content
OpenSearch is a scalable, flexible, and extensible open-source software suite for search, analytics, and observability applications licensed under Apache 2.0. OpenSearch is a distributed search and analytics engine based on Apache Lucene.
This notebook shows how to use functionality related to the OpenSearch database. To run, you should have an OpenSearch instance up and running: see here for an easy Docker installation. similarity_search by default performs the Approximate k-NN Search which uses one of the several algorithms like lucene, nmslib, faiss recommended for large datasets. To perform brute force search we have other search methods known as Script Scoring and Painless Scripting. Check this for more details.

Installation

Install the Python client.
We want to use OpenAIEmbeddings so we have to get the OpenAI API Key.

similarity_search using approximate k-NN

similarity_search using Approximate k-NN Search with Custom Parameters

similarity_search using script scoring

similarity_search using Script Scoring with Custom Parameters

similarity_search using painless scripting

similarity_search using Painless Scripting with Custom Parameters

Maximum marginal relevance search (MMR)

If you’d like to look up for some similar documents, but you’d also like to receive diverse results, MMR is method you should consider. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.

Using a preexisting OpenSearch instance

It’s also possible to use a preexisting OpenSearch instance with documents that already have vectors present.

Using AOSS (Amazon OpenSearch Service serverless)

It is an example of the AOSS with faiss engine and efficient_filter. We need to install several python packages.

Using AOS (Amazon OpenSearch Service)


Connect these docs to Claude, VSCode, and more via MCP for real-time answers.