Skip to content

Commit e51abf2

Browse files
committed
demo
1 parent 8836867 commit e51abf2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

langchain/vectorstores/demo.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from langchain.vectorstores import Spellbook, VectorStore
2+
from langchain.embeddings.openai import OpenAIEmbeddings
3+
import requests
4+
5+
# create a vector store via REST api
6+
res = requests.post('https://api.spellbook.scale.com/create_vector_store', json={
7+
"name": "cat facts",
8+
}, headers={
9+
"authorization": "...",
10+
})
11+
assert res.status_code == 200
12+
13+
# add documents to vectorstores
14+
spellbook: VectorStore = Spellbook(api_key="...", name="cat facts")
15+
embeddings = OpenAIEmbeddings()
16+
spellbook.add_texts(texts=[
17+
"cats are fun",
18+
], embeddings=embeddings)
19+
20+
# query
21+
query = "what's up?"
22+
query_embedding = embeddings.embed_query(query)
23+
24+
docs = spellbook.similarity_search_by_vector(query_embedding)

0 commit comments

Comments
 (0)