Zack Saadioui
8/24/2024
1
2
bash
pip install langchain-qdrant qdrant-client langchain-openai
1
2
3
python
from qdrant_client import QdrantClient
qdrant_client = QdrantClient("http://localhost:6333")
1
2
3
4
5
python
qdrant_client.create_collection(
collection_name="my_vectors",
vectors_config={"size": 768, "distance": "Cosine"}
)
1
2
3
4
5
6
7
8
9
python
from langchain_qdrant import QdrantVectorStore
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
vector_store = QdrantVectorStore(
client=qdrant_client,
collection_name="my_vectors",
embedding=embeddings
)
1
2
3
4
python
from langchain.document_loaders import TextLoader
loader = TextLoader("path/to/your/textfile.txt")
documents = loader.load()
1
2
python
vector_store.add_documents(documents)
1
2
3
4
5
python
query = "What are the uses of AI in modern applications?"
results = vector_store.similarity_search(query)
for res in results:
print(res.page_content, res.metadata)
1
2
3
4
5
python
embedding_vector = embeddings.embed_query(query)
results = vector_store.similarity_search_by_vector(embedding_vector)
for res in results:
print(res.page_content, res.metadata)
1
hnsw_ef
Copyright © Arsturn 2024