```python
from langchain.document_loaders import TextLoader
loader = TextLoader('../../../state_of_the_union.txt')
```


```python
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import FAISS
from langchain.embeddings import OpenAIEmbeddings

documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
db = FAISS.from_documents(texts, embeddings)
```

<CodeOutputBlock lang="python">

```
    Exiting: Cleaning up .chroma directory
```

</CodeOutputBlock>


```python
retriever = db.as_retriever()
```


```python
docs = retriever.get_relevant_documents("what did he say about ketanji brown jackson")
```

## Maximum Marginal Relevance Retrieval
By default, the vectorstore retriever uses similarity search. If the underlying vectorstore support maximum marginal relevance search, you can specify that as the search type.


```python
retriever = db.as_retriever(search_type="mmr")
```


```python
docs = retriever.get_relevant_documents("what did he say abotu ketanji brown jackson")
```

## Similarity Score Threshold Retrieval

You can also a retrieval method that sets a similarity score threshold and only returns documents with a score above that threshold


```python
retriever = db.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": .5})
```


```python
docs = retriever.get_relevant_documents("what did he say abotu ketanji brown jackson")
```

## Specifying top k
You can also specify search kwargs like `k` to use when doing retrieval.


```python
retriever = db.as_retriever(search_kwargs={"k": 1})
```


```python
docs = retriever.get_relevant_documents("what did he say abotu ketanji brown jackson")
```


```python
len(docs)
```

<CodeOutputBlock lang="python">

```
    1
```

</CodeOutputBlock>
