Skip to content

Commit 0d89dac

Browse files
committed
Initial Commit
0 parents  commit 0d89dac

File tree

8 files changed

+139
-0
lines changed

8 files changed

+139
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:latest
2+
3+
COPY requirements.txt .
4+
# COPY .env .
5+
COPY app.py .
6+
7+
RUN pip install -r requirements.txt
8+
9+
CMD ["python", "app.py"]

app.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
3+
from langchain.vectorstores.neo4j_vector import Neo4jVector
4+
from langchain.document_loaders import WikipediaLoader
5+
from langchain.embeddings.openai import OpenAIEmbeddings
6+
from langchain.text_splitter import CharacterTextSplitter
7+
from langchain.docstore.document import Document
8+
from dotenv import load_dotenv
9+
10+
load_dotenv('.env')
11+
12+
url = os.getenv('NEO4J_URI')
13+
username = os.getenv('NEO4J_USERNAME')
14+
password = os.getenv('NEO4J_PASSWORD')
15+
page = os.getenv('WIKIPEDIA_PAGE') or "Sweden"
16+
prompt = os.getenv('PROMPT') or "What is the second largest city in Sweden?"
17+
18+
os.environ["NEO4J_URL"] = url
19+
20+
embeddings = OpenAIEmbeddings()
21+
22+
# Read the wikipedia article
23+
raw_documents = WikipediaLoader(query=page).load()
24+
25+
# Define chunking strategy
26+
text_splitter = CharacterTextSplitter.from_tiktoken_encoder(
27+
chunk_size=1000, chunk_overlap=20
28+
)
29+
# Chunk the document
30+
documents = text_splitter.split_documents(raw_documents)
31+
# Remove the summary
32+
for d in documents:
33+
del d.metadata["summary"]
34+
35+
neo4j_db = Neo4jVector.from_documents(
36+
documents,
37+
embedding=embeddings,
38+
url=url,
39+
username=username,
40+
password=password,
41+
database="neo4j", # neo4j by default
42+
index_name="wikipedia", # vector by default
43+
node_label="WikipediaArticle", # Chunk by default
44+
text_node_property="info", # text by default
45+
embedding_node_property="vector", # embedding by default
46+
create_id_index=True, # True by default
47+
)
48+
49+
neo4j_db.add_documents(
50+
[
51+
Document(
52+
page_content="LangChain is the coolest library since the Library of Alexandria",
53+
metadata={"author": "Tomaz", "confidence": 1.0}
54+
)
55+
],
56+
ids=["langchain"],
57+
)
58+
59+
result = neo4j_db.similarity_search(prompt, k=1)
60+
61+
print(result)

docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
services:
3+
4+
database:
5+
image: neo4j:latest
6+
ports:
7+
- 7687:7687
8+
- 7474:7474
9+
environment:
10+
- NEO4J_AUTH=neo4j/password
11+
# - NEO4J_ACCEPT_LICENSE_AGREEMENT=developer
12+
networks:
13+
- net
14+
15+
langchain-app:
16+
build: .
17+
18+
environment:
19+
- NEO4J_URI=neo4j://database:7687
20+
- NEO4J_PASSWORD=password
21+
- NEO4J_USERNAME=neo4j
22+
- OPENAI_API_KEY=${OPENAI_API_KEY}
23+
networks:
24+
- net
25+
depends_on:
26+
- database
27+
28+
ports:
29+
- 8080:8080
30+
31+
networks:
32+
net:

example.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OPENAI_API_KEY=sk-...
2+
NEO4J_URI=neo4j://localhost:7687
3+
NEO4J_USERNAME=neo4j
4+
NEO4J_PASSWORD=password

readme.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# LangChain Docker Starter Kits
2+
3+
4+
## Create Graph App
5+
6+
### Endpoints
7+
8+
* `/add_page?title=pagename`
9+
* `/clear`
10+
11+
## QA Bot App (RAG)
12+
13+
* `/answer?title=
14+
15+
For control plane / extension - or env-variables
16+
17+
* `/prompt` POST / GET
18+
* `/configure` (temperature, top-k, ...)
19+
20+
## Neo4j
21+
22+

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
langchain
2+
openai
3+
python-dotenv
4+
wikipedia
5+
tiktoken
6+
neo4j

start.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
docker run --name neo4j -e NEO4J_AUTH=neo4j/password -p 7687:7687 -p 7474:7474 neo4j:latest
2+
3+
# docker ps -qaf name=neo4j

0 commit comments

Comments
 (0)