Spaces:
Sleeping
Sleeping
junlin3
commited on
Commit
·
f43e234
1
Parent(s):
451f29e
向量库改为FAISS,解决Chroma和Google库里对pb不同版本的依赖问题
Browse files- agent.py +19 -4
- requirements.txt +13 -164
- requirements.txt.backup +1 -2
agent.py
CHANGED
@@ -9,9 +9,13 @@ from langchain_core.messages import HumanMessage, SystemMessage
|
|
9 |
from langchain_ollama import ChatOllama
|
10 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
11 |
from langchain_huggingface import HuggingFaceEmbeddings, ChatHuggingFace, HuggingFaceEndpoint
|
12 |
-
from langchain_chroma import Chroma
|
13 |
from langgraph.graph import START, StateGraph, MessagesState
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
from langgraph.prebuilt import ToolNode
|
16 |
from langgraph.prebuilt import tools_condition
|
17 |
|
@@ -134,10 +138,21 @@ sys_msg = SystemMessage(content=system_prompt)
|
|
134 |
|
135 |
# Retriever
|
136 |
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-small-en-v1.5")
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
embedding_function=embeddings,
|
140 |
-
|
|
|
|
|
141 |
)
|
142 |
create_retriever_tool = create_retriever_tool(
|
143 |
retriever= vector_store.as_retriever(),
|
|
|
9 |
from langchain_ollama import ChatOllama
|
10 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
11 |
from langchain_huggingface import HuggingFaceEmbeddings, ChatHuggingFace, HuggingFaceEndpoint
|
|
|
12 |
from langgraph.graph import START, StateGraph, MessagesState
|
13 |
|
14 |
+
# from langchain_chroma import Chroma
|
15 |
+
import faiss
|
16 |
+
from langchain_community.docstore.in_memory import InMemoryDocstore
|
17 |
+
from langchain_community.vectorstores import FAISS
|
18 |
+
|
19 |
from langgraph.prebuilt import ToolNode
|
20 |
from langgraph.prebuilt import tools_condition
|
21 |
|
|
|
138 |
|
139 |
# Retriever
|
140 |
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-small-en-v1.5")
|
141 |
+
|
142 |
+
# vector_store = Chroma(
|
143 |
+
# collection_name="demo_collection",
|
144 |
+
# embedding_function=embeddings,
|
145 |
+
# persist_directory="./chroma_langchain_db",
|
146 |
+
# )
|
147 |
+
|
148 |
+
embedding_dim = len(embeddings.embed_query("hello world"))
|
149 |
+
index = faiss.IndexFlatL2(embedding_dim)
|
150 |
+
|
151 |
+
vector_store = FAISS(
|
152 |
embedding_function=embeddings,
|
153 |
+
index=index,
|
154 |
+
docstore=InMemoryDocstore(),
|
155 |
+
index_to_docstore_id={},
|
156 |
)
|
157 |
create_retriever_tool = create_retriever_tool(
|
158 |
retriever= vector_store.as_retriever(),
|
requirements.txt
CHANGED
@@ -1,164 +1,13 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
cachetools==5.5.2
|
15 |
-
certifi==2025.4.26
|
16 |
-
charset-normalizer==3.4.2
|
17 |
-
chromadb==1.0.12
|
18 |
-
click==8.2.1
|
19 |
-
coloredlogs==15.0.1
|
20 |
-
dataclasses-json==0.6.7
|
21 |
-
distro==1.9.0
|
22 |
-
durationpy==0.10
|
23 |
-
fastapi==0.115.9
|
24 |
-
ffmpy==0.6.0
|
25 |
-
filelock==3.18.0
|
26 |
-
filetype==1.2.0
|
27 |
-
flatbuffers==25.2.10
|
28 |
-
frozenlist==1.7.0
|
29 |
-
fsspec==2025.5.1
|
30 |
-
google-ai-generativelanguage==0.6.18
|
31 |
-
google-api-core==2.25.1
|
32 |
-
google-auth==2.40.3
|
33 |
-
googleapis-common-protos==1.70.0
|
34 |
-
gradio==5.34.0
|
35 |
-
gradio_client==1.10.3
|
36 |
-
groovy==0.1.2
|
37 |
-
grpcio==1.73.0
|
38 |
-
grpcio-status==1.73.0
|
39 |
-
h11==0.16.0
|
40 |
-
hf-xet==1.1.3
|
41 |
-
httpcore==1.0.9
|
42 |
-
httptools==0.6.4
|
43 |
-
httpx==0.28.1
|
44 |
-
httpx-sse==0.4.0
|
45 |
-
huggingface-hub==0.33.0
|
46 |
-
humanfriendly==10.0
|
47 |
-
idna==3.10
|
48 |
-
importlib_metadata==8.7.0
|
49 |
-
importlib_resources==6.5.2
|
50 |
-
Jinja2==3.1.6
|
51 |
-
joblib==1.5.1
|
52 |
-
jsonpatch==1.33
|
53 |
-
jsonpointer==3.0.0
|
54 |
-
jsonschema==4.24.0
|
55 |
-
jsonschema-specifications==2025.4.1
|
56 |
-
kubernetes==33.1.0
|
57 |
-
langchain==0.3.25
|
58 |
-
langchain-chroma==0.2.4
|
59 |
-
langchain-community==0.3.25
|
60 |
-
langchain-core==0.3.65
|
61 |
-
langchain-google-genai==2.1.5
|
62 |
-
langchain-huggingface==0.3.0
|
63 |
-
langchain-ollama==0.3.3
|
64 |
-
langchain-text-splitters==0.3.8
|
65 |
-
langgraph==0.4.8
|
66 |
-
langgraph-checkpoint==2.0.26
|
67 |
-
langgraph-prebuilt==0.2.2
|
68 |
-
langgraph-sdk==0.1.70
|
69 |
-
langsmith==0.3.45
|
70 |
-
markdown-it-py==3.0.0
|
71 |
-
MarkupSafe==3.0.2
|
72 |
-
marshmallow==3.26.1
|
73 |
-
mdurl==0.1.2
|
74 |
-
mmh3==5.1.0
|
75 |
-
mpmath==1.3.0
|
76 |
-
multidict==6.4.4
|
77 |
-
mypy_extensions==1.1.0
|
78 |
-
networkx==3.5
|
79 |
-
numpy==2.3.0
|
80 |
-
oauthlib==3.2.2
|
81 |
-
ollama==0.5.1
|
82 |
-
onnxruntime==1.22.0
|
83 |
-
opentelemetry-api==1.34.1
|
84 |
-
opentelemetry-exporter-otlp-proto-common==1.34.1
|
85 |
-
opentelemetry-exporter-otlp-proto-grpc==1.34.1
|
86 |
-
opentelemetry-instrumentation==0.55b1
|
87 |
-
opentelemetry-instrumentation-asgi==0.55b1
|
88 |
-
opentelemetry-instrumentation-fastapi==0.55b1
|
89 |
-
opentelemetry-proto==1.34.1
|
90 |
-
opentelemetry-sdk==1.34.1
|
91 |
-
opentelemetry-semantic-conventions==0.55b1
|
92 |
-
opentelemetry-util-http==0.55b1
|
93 |
-
orjson==3.10.18
|
94 |
-
ormsgpack==1.10.0
|
95 |
-
overrides==7.7.0
|
96 |
-
packaging==24.2
|
97 |
-
pandas==2.3.0
|
98 |
-
pillow==11.2.1
|
99 |
-
pip_search==0.0.13
|
100 |
-
posthog==4.8.0
|
101 |
-
propcache==0.3.2
|
102 |
-
proto-plus==1.26.1
|
103 |
-
protobuf==5.29.5
|
104 |
-
pyasn1==0.6.1
|
105 |
-
pyasn1_modules==0.4.2
|
106 |
-
pydantic==2.11.5
|
107 |
-
pydantic-settings==2.9.1
|
108 |
-
pydantic_core==2.33.2
|
109 |
-
pydub==0.25.1
|
110 |
-
Pygments==2.19.1
|
111 |
-
PyPika==0.48.9
|
112 |
-
pyproject_hooks==1.2.0
|
113 |
-
python-dateutil==2.9.0.post0
|
114 |
-
python-dotenv==1.1.0
|
115 |
-
python-multipart==0.0.20
|
116 |
-
pytz==2025.2
|
117 |
-
PyYAML==6.0.2
|
118 |
-
referencing==0.36.2
|
119 |
-
regex==2024.11.6
|
120 |
-
requests==2.32.4
|
121 |
-
requests-oauthlib==2.0.0
|
122 |
-
requests-toolbelt==1.0.0
|
123 |
-
rich==14.0.0
|
124 |
-
rpds-py==0.25.1
|
125 |
-
rsa==4.9.1
|
126 |
-
ruff==0.11.13
|
127 |
-
safehttpx==0.1.6
|
128 |
-
safetensors==0.5.3
|
129 |
-
scikit-learn==1.7.0
|
130 |
-
scipy==1.15.3
|
131 |
-
semantic-version==2.10.0
|
132 |
-
sentence-transformers==4.1.0
|
133 |
-
setuptools==80.9.0
|
134 |
-
shellingham==1.5.4
|
135 |
-
six==1.17.0
|
136 |
-
sniffio==1.3.1
|
137 |
-
soupsieve==2.7
|
138 |
-
SQLAlchemy==2.0.41
|
139 |
-
starlette==0.45.3
|
140 |
-
sympy==1.14.0
|
141 |
-
tenacity==9.1.2
|
142 |
-
threadpoolctl==3.6.0
|
143 |
-
tokenizers==0.21.1
|
144 |
-
tomlkit==0.13.3
|
145 |
-
torch==2.7.1
|
146 |
-
tqdm==4.67.1
|
147 |
-
transformers==4.52.4
|
148 |
-
typer==0.16.0
|
149 |
-
typing-inspect==0.9.0
|
150 |
-
typing-inspection==0.4.1
|
151 |
-
typing_extensions==4.14.0
|
152 |
-
tzdata==2025.2
|
153 |
-
urllib3==2.4.0
|
154 |
-
uvicorn==0.34.3
|
155 |
-
uvloop==0.21.0
|
156 |
-
watchfiles==1.0.5
|
157 |
-
websocket-client==1.8.0
|
158 |
-
websockets==15.0.1
|
159 |
-
wikipedia==1.4.0
|
160 |
-
wrapt==1.17.2
|
161 |
-
xxhash==3.5.0
|
162 |
-
yarl==1.20.1
|
163 |
-
zipp==3.23.0
|
164 |
-
zstandard==0.23.0
|
|
|
1 |
+
gradio
|
2 |
+
requests
|
3 |
+
langchain
|
4 |
+
langchain-community
|
5 |
+
langchain-core
|
6 |
+
langchain-google-genai
|
7 |
+
langchain-huggingface
|
8 |
+
sentence-transformers
|
9 |
+
faiss-cpu
|
10 |
+
langchain-ollama
|
11 |
+
langgraph
|
12 |
+
wikipedia
|
13 |
+
python-dotenv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt.backup
CHANGED
@@ -6,8 +6,7 @@ langchain-core
|
|
6 |
langchain-google-genai
|
7 |
langchain-huggingface
|
8 |
sentence-transformers
|
9 |
-
|
10 |
-
langchain-chroma
|
11 |
langchain-ollama
|
12 |
langgraph
|
13 |
wikipedia
|
|
|
6 |
langchain-google-genai
|
7 |
langchain-huggingface
|
8 |
sentence-transformers
|
9 |
+
faiss-cpu
|
|
|
10 |
langchain-ollama
|
11 |
langgraph
|
12 |
wikipedia
|