Start using Rockset to search for documents similar to your search queries.1. Define Key Variables‚Äãimport osimport rocksetROCKSET_API_KEY = os.environ.get("ROCKSET_API_KEY") # Verify ROCKSET_API_KEY environment variableROCKSET_API_SERVER = rockset.Regions.usw2a1 # Verify Rockset regionrockset_client = rockset.RocksetClient(ROCKSET_API_SERVER, ROCKSET_API_KEY)COLLECTION_NAME='langchain_demo'TEXT_KEY='description'EMBEDDING_KEY='description_embedding'2. Prepare Documents‚Äãfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.text_splitter import CharacterTextSplitterfrom langchain.document_loaders import TextLoaderfrom langchain.vectorstores import Rocksetloader = TextLoader('../../modules/state_of_the_union.txt')documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)docs = text_splitter.split_documents(documents)3. Insert Documents‚Äãembeddings = OpenAIEmbeddings() # Verify OPENAI_API_KEY environment variabledocsearch = Rockset(    client=rockset_client,    embeddings=embeddings,    collection_name=COLLECTION_NAME,    text_key=TEXT_KEY,    embedding_key=EMBEDDING_KEY,)ids=docsearch.add_texts(    texts=[d.page_content for d in docs],    metadatas=[d.metadata for d in docs],)4. Search for Similar Documents‚Äãquery = "What did the president say about Ketanji Brown Jackson"output = docsearch.similarity_search_with_relevance_scores(    query, 4, Rockset.DistanceFunction.COSINE_SIM)print("output length:", len(output))for d, dist in output:    print(dist, d.metadata, d.page_content[:20] + '...')### output length: 4# 0.764990692109871 {'source': '../../../state_of_the_union.txt'} Madam Speaker, Madam...# 0.7485416901622112 {'source': '../../../state_of_the_union.txt'} And I‚Äôm taking robus...# 0.7468678973398306 {'source': '../../../state_of_the_union.txt'} And so many families...# 0.7436231261419488 {'source': '../../../state_of_the_union.txt'} Groups of citizens b...5. Search for Similar Documents with
Rockset is a real-time search and analytics database built for the cloud. Rockset uses a Converged Index‚Ñ¢ with an efficient store for vector embeddings to serve low latency, high concurrency search queries at scale. Rockset has full support for metadata filtering and  handles real-time ingestion for constantly updating, streaming data.
Rockset is a real-time search and analytics database built for the cloud. Rockset uses a Converged Index‚Ñ¢ with an efficient store for vector embeddings to serve low latency, high concurrency search queries at scale. Rockset has full support for metadata filtering and  handles real-time ingestion for constantly updating, streaming data. ->: Start using Rockset to search for documents similar to your search queries.1. Define Key Variables‚Äãimport osimport rocksetROCKSET_API_KEY = os.environ.get("ROCKSET_API_KEY") # Verify ROCKSET_API_KEY environment variableROCKSET_API_SERVER = rockset.Regions.usw2a1 # Verify Rockset regionrockset_client = rockset.RocksetClient(ROCKSET_API_SERVER, ROCKSET_API_KEY)COLLECTION_NAME='langchain_demo'TEXT_KEY='description'EMBEDDING_KEY='description_embedding'2. Prepare Documents‚Äãfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.text_splitter import CharacterTextSplitterfrom langchain.document_loaders import TextLoaderfrom langchain.vectorstores import Rocksetloader = TextLoader('../../modules/state_of_the_union.txt')documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)docs = text_splitter.split_documents(documents)3. Insert Documents‚Äãembeddings = OpenAIEmbeddings() # Verify OPENAI_API_KEY environment variabledocsearch = Rockset(    client=rockset_client,    embeddings=embeddings,    collection_name=COLLECTION_NAME,    text_key=TEXT_KEY,    embedding_key=EMBEDDING_KEY,)ids=docsearch.add_texts(    texts=[d.page_content for d in docs],    metadatas=[d.metadata for d in docs],)4. Search for Similar Documents‚Äãquery = "What did the president say about Ketanji Brown Jackson"output = docsearch.similarity_search_with_relevance_scores(    query, 4, Rockset.DistanceFunction.COSINE_SIM)print("output length:", len(output))for d, dist in output:    print(dist, d.metadata, d.page_content[:20] + '...')### output length: 4# 0.764990692109871 {'source': '../../../state_of_the_union.txt'} Madam Speaker, Madam...# 0.7485416901622112 {'source': '../../../state_of_the_union.txt'} And I‚Äôm taking robus...# 0.7468678973398306 {'source': '../../../state_of_the_union.txt'} And so many families...# 0.7436231261419488 {'source': '../../../state_of_the_union.txt'} Groups of citizens b...5. Search for Similar Documents with