Faiss Vector Store
Source: llama_index

<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/docs/examples/vector_stores/FaissIndexDemo.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a># Faiss Vector StoreIf you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.```python%pip install llama-index-vector-stores-faiss``````python!pip install llama-index```#### Creating a Faiss Index```pythonimport loggingimport syslogging.basicConfig(stream=sys.stdout, level=logging.INFO)logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))``````pythonimport faiss# dimensions of text-ada-embedding-002d = 1536faiss_index = faiss.IndexFlatL2(d)```#### Load documents, build the VectorStoreIndex```pythonfrom llama_index.core import (    SimpleDirectoryReader,    load_index_from_storage,    VectorStoreIndex,    StorageContext,)from llama_index.vector_stores.faiss import FaissVectorStorefrom IPython.display import Markdown, display```Download Data```python!mkdir -p 'data/paul_graham/'!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'``````python# load documentsdocuments = SimpleDirectoryReader("./data/paul_graham/").load_data()``````pythonvector_store = FaissVectorStore(faiss_index=faiss_index)storage_context = StorageContext.from_defaults(vector_store=vector_store)index = VectorStoreIndex.from_documents(    documents, storage_context=storage_context)``````python# save index to diskindex.storage_context.persist()``````python# load index from diskvector_store = FaissVectorStore.from_persist_dir("./storage")storage_context = StorageContext.from_defaults(    vector_store=vector_store, persist_dir="./storage")index = load_index_from_storage(storage_context=storage_context)```#### Query Index```python# set Logging to DEBUG for more detailed outputsquery_engine = index.as_query_engine()response = query_engine.query("What did the author do growing up?")``````pythondisplay(Markdown(f"<b>{response}</b>"))``````python# set Logging to DEBUG for more detailed outputsquery_engine = index.as_query_engine()response = query_engine.query(    "What did the author do after his time at Y Combinator?")``````pythondisplay(Markdown(f"<b>{response}</b>"))```